Core Java Interview Questions- Part 8

Core Java Interview Questions- Part 8
Java is a powerful programming language that has ruled for decades. It’s used in mobile apps to large business software and now even in IOT devices, Cloud Computing, AI, and ML. Because of its strong reputation, Java is a skill that many companies look for when hiring developers.
If you’re getting ready for a Java job interview, it’s important to prepare well. Interviewers may ask you about Java basics, object-oriented programming, loops, conditions, memory management, or more complex topics like multithreading and collections. The better you understand these ideas, the more confident you’ll feel in the interview.
This page is here to help you. It includes a list of the most common and important Java interview questions. You’ll find clear answers that are easy to understand and explain. These questions will help you review your knowledge, find any weak spots, and improve your skills.
Whether you’re applying for your first job or switching to a new one, these questions can help you get ready. So take your time, study each question, and keep practicing. Your hard work will pay off in the interview.

Answer:

Serializable interface helps to make classes serializable, enabling them to transfer over a network or be saved on disk. However, it leverages default serialization built-in Java Virtual Machine, which is fragile, expensive, & not secure. Externalizable enables you to fully control the process of Serialization by specifying a custom binary format & add more security measures.

Answer:

Yes, we can use String in the switch case. However, you must consider the following things in mind while doing so:

  • It is advisable to use String values in a switch case, if the data you are dealing with is Strings.
  • The comparison of Strings in the switch statement is case sensitive. i.e., the String you have passed & the String of the case should be equal and in same the case (upper or lower).
  • The switch case expression must not be null; otherwise, a NullPointerException is thrown during runtime.

Answer:

Serialization implies a mechanism that converts an object’s state into a byte stream. Deserialization is the reverse process, wherein the byte stream helps recreate the actual Java object in the memory.

Answer:

Following are the major differences between checked & unchecked exceptions in Java

  • Checked exceptions occur at compile time. While, Unchecked exceptions occur at runtime.
  • During checked exceptions the compiler checks a checked exception. Whereas, in unchecked exceptions the compiler does not check these types of exceptions.
  • Checked exceptions can be handled at the time of compilation. On the other hand, unchecked exceptions cannot be a catch or handle at the time of compilation, because they get generated by the mistakes in the program.
  • In, checked exceptions JVM needs the exception to catch and handle. In contrast, JVM does not require the exception to catch and handle.

Answer:

The clone() method of the Object class helps to clone an object. The java.lang. Cloneable interface needs to be implemented by the class whose object clone we want to create.

Answer:

Follow these simple steps to compile a Java program:

  • Open a command prompt window & go to the directory in which you have saved the Java program. Suppose it is C:\.
  • Thereon, type ‘javac MyFirstJavaProgram.java’ & press enter to compile your Java code. If your code is error-free, then the command prompt will take you to the next line.

Answer:

The variables that are declared inside the class but outside the scope of any method are called instance variables in Java.

Answer:

Maven is a robust Java project management tool based on (project object model) POM. It is used for building projects, documentation, & dependency. Maven simplifies the build process like ANT but is far more advanced than ANT.

Answer:

An array in Java is a container object with a fixed number of values of a similar type. When an array is being created, its length is established & after creation, the length remains fixed.

Answer:

An applet refers to a special type of program that runs in a Java-enabled browser. It is the first program in Java that can run over the network via a browser. It is typically embedded inside the web page & runs in the browser.

Answer:

The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time.

Answer:

A Stream is a sequence of elements in Java from one source. It supports aggregate operations on the elements. Aggregate operations enable us to clearly & quickly express common manipulations on the stream elements.

Answer:

A lambda expression means a block of code or an anonymous function that can be passed to methods or constructors for subsequent execution. The method or constructor receives the lambda as an argument.

Answer:

Microservices in Java are a form of service-oriented architecture style in which applications get developed as a set of different smaller services instead of a single complete application.

Answer:

Typecasting is the process of converting the value of a data type like float, int, or double, to another data type.

Answer:

Follow any of these approaches to add a new element to an array in Java:

  • Use a new array greater than the original one;
  • Use ArrayList as an intermediate structure;
  • Shift the elements to accommodate a new element.

Answer:

To call a method, write the name of the method followed by two parentheses () and a ; (semicolon).

Answer:

The next() method can read the input only till the space character, but it cannot read two words separated by the space. The next() also places the cursor in the same line after reading the input. The nextLine() reads input, including words having space in between; thus, it reads till the end of a line. The nextLine() positions the cursor in the next line once the input is read.

Answer:

MVC stands for Model-View-Controller pattern. It is used to separate the application’s interests. Here, the model means an object or JAVA POJO conveying data. A view is the visualization of data that contains the model, and controllers act on both model and the view. It controls the data flow into model object and updates the view whenever data changes. It keeps view and model separate.