Advanced Java Interview Questions- Part 2

Advanced Java Interview Questions- Part 2Our Advanced Java Interview Questions- Part 2 is your ultimate guide to clearing advanced Java interviews with confidence. Java has remained one of the world’s top four programming languages for over 20 years, according to the TIOBE Index.

While many new languages have tried to replace it, Java is still widely used and in demand, even in 2025. A quick search for “Java” jobs in the U.S. will show thousands of openings. But before applying, it’s important to prepare for Java interview questions.

Top skills like Spring Boot, microservices, and cloud computing (AWS, Azure) are essential for building scalable, modern apps. Our interview questions with answers, perfect, will help you master tough concepts like multithreading, REST APIs, and JVM. Start learning now to stand out in interviews and land a high-paying Java job.

Answer:

To serialize a class instance, you need to implement an interface serializable & then pass the instance to the ObjectOutputStream connected to a FileOutputStream. Thus, it will save the object to a file.

Answer:

The Serializable interface is also a marker interface that does not have any methods & fields. Thus, a class implementing Serializable does not have to implement any methods.

Answer:

Serialization generates an object graph for serialization. It checks if the included object references are serializable or not. It is a recursive process; means if an object is serialized, all the included objects also get serialized along with that object.

Answer:

Static variables do not belong to any individual instance; instead, they belong to an object. Besides, serialization only regards the object’s current state, so only data associated with a class’s specific instance gets serialized. Thus, the static member fields are usually ignored during serialization.

Answer:

When an exception is thrown from the code wrapped in a try block, a search is made to match a catch block. If it finds a matching type, then that block is invoked. However, if it fails to find a matching type, the exception moves up the method stack & reaches the caller method.

Answer:

Java Observer pattern is used in the design. When the state of an observable object changes, its corresponding observer classes get notified. An Observable implement as a class that includes methods to manage Observers list & notifying Observers.

Answer:

Java does not handle or deal with integer overflows & underflows. The values are wrapped around by adding one to the maximum values of a primitive data type that returns the minimum value.

Answer:

Below are the key differences between Exceptions & Errors:

Errors Exceptions
Errors are raised by the environment when the application is running. For instance, an error will occur due to fewer system resources. Exceptions occur by the code of the application itself.
It isn’t possible to recover from an error. One can handle the exception by using try-catch blocks & recover the application from them.
The compiler does not know the error; hence, it gets classified as “unchecked.” An exception can be checked or unchecked, which means it may or may not get caught by the compiler.
Some examples of errors are “OutOfMemory” and “StackOverflow.”  “ClassNotFound” is the example of a checked exception, while “IndexOutOfBounds” is an unchecked exception.

Answer:

Static class is a way of grouping together the classes in Java. As Java doesn’t allow you to create top-level static classes, except the inner or nested classes, a static class is known as a static nested class or static inner class.

Answer:

A JavaBean is a class that satisfies the following programming conventions:

It must implement either Externalizable or Serializable.

JavaBean needs to have a no-arg constructor.

All the properties of JavaBean must have public setter & getter methods.

JavaBean instance variables must be private.

Answer:

The Java Virtual Machine has a heap, a runtime data area that allocates the memory for all the class instances & arrays. It is created during JVM start-up & shared by all the threads inside the Java Virtual Machines. When the heap storage is not used, it is reclaimed by the garbage collector. JVM throws OutOfMemoryError if the computation needs more heap than what could be supplied by the automatic storage management system.

Answer:

The following are the key differences between the throw & throws:

Sr. No. Key Throw Throws
1 Definition The throw is a keyword used to explicitly throw an exception in the program or inside a block of code. Throws keyword is used to declare an exception that might get thrown by the function during code execution.
2 Internal implementation Internally, the throw keyword can only throw a single exception at a time. One can declare multiple exceptions with the throws keyword.
3 Type of exception With the throw keyword, one can propagate unchecked exceptions only; thus, the checked exception cannot be propagated with the throw keyword. With the throws keyword, one can declare both checked & unchecked exceptions.
4 Syntax The instance variable follows the throw keyword. The exception class names follow the throws keyword.
5 Declaration The throw keyword is used within the method. Throws keyword is used with the method signature.

Answer:

A session is a dynamic state of the random conversation between the server & the client. The communication channel consists of a string of responses & requests from both sides. There are several ways of session management such as cookie session management API, user authentication, HTML hidden field & URL rewriting., The most popular way of session management implementation is the employment of a session ID into the client’s communicative discourse & the server.

Answer:

The core or central purpose of the JDBC ResultSet Interface is to represent a row in a table or show the result set of a database. Besides, it is also helpful for altering the cursor pointer and churn information from the database.

Answer:

The main advantage of using an ordered array is that the search times are faster with O (log n) than an unordered array O (n). However, an ordered array’s disadvantage is that the insertion operation takes longer O(n) because the elements with higher values are compelled to be moved to make room for new elements. On the other hand, the insertion operation for an unordered array takes a constant time of O(1).

Answer:

Java transient keyword helps to indicate that a field is not a part of the serialization process. The modifier transient applies to a particular member variable of a class to turn off serialization on that member variable. Each field marked as transient will not be serialized.

Answer:

As the name suggests, multiple inheritance is the process wherein a child class inherits multiple parent classes’ properties. If multiple inheritance is supported, it creates a Diamond problem that further creates problems during casting, chaining, etc. So, Java supports multi-inheritance through single inheritance with interfaces to overcome such issues.

Answer:

Java Servlet is a server-side module that answers client requests. It helps in enhancing the functionality of a web server with minimal maintenance, support, & overhead. It acts as an intermediary between the client & the server. As servlet modules run on the server, it can receive & respond to the client’s requests. Response & request objects of the Java servlet provide a convenient way to handle HTTP requests & send back text data to the client.

Answer:

Threads block on I/O (that enters the waiting state) so that the other threads may execute when the I/O Operation is performed.

Answer:

No, a null value is not a keyword. It is a reserved word for the literal values.