Java Interview Questions and Answers 2 | Intermediate Level

Here are a few intermediate level Java Interview Questions and Answers. This post’s interview questions and answers are mostly useful for 2-4 experienced candidates.

Java Interview Questions
Java Interview Questions

Java Interview Question and Answers

  1. What is the difference between this and super in Java?

– this and super are keywords in Java; both keywords are used to access variables and methods. this keyword is used to refer to the current class instance, and super is used to represent superclass reference from subclass

2. What is serializable in Java?

Serialization is the process of converting the state of an object into a byte stream. If you want a class object to be serializable, then you need to implement the java.io.Serializable interface. Serializable marker interface in Java and has no fields or methods to implement.

– Deserialization is the process of converting byte stream to the actual Java object in memory. 

3. What is transient in Java?

– The transient keyword is used to avoid Serialization. If we define any data member as transient, It will not be serialized.

– If JVM finds any data member defined as a transient, it ignores the variable’s original value and saves the default value.

4. What is the volatile keyword?

– If any variable is defined as volatile, then the value of the variable is not cached. The value of that variable always gets from the main memory instead of cached memory.

– volatile keyword is applicable for variables, methods, and classes. If a variable is volatile, then the variable is thread-safe multiple threads can operate on that variable simultaneously. 

5. What is the final keyword in Java?

– final is a keyword in Java. It applies to variables, methods, and classes.

– If a variable is final then the values of the variable becomes constant we cannot change the value of the variable

– If a method is final then we cannot override the method in subclasses

– If a class is final, then we cannot extend the class.

6. What are wrapper classes in Java?

– Wrapper classes are used to convert primitive data types to objects and vice-versa.

– Data Structures like ArrayList and Vector store only objects not primitives (because values pass primitives).

7. What are autoboxing and auto unboxing?

– The Automatic conversion of primitives to their corresponding wrapper classes is called autoboxing.

  Example: int to Integer, long to Long, double to Double

– The Automatic conversion of wrapper classes to their corresponding primitives is called auto unboxing.

  Example: Integer to int, Long to long, Double to double

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top