Java Interview Questions for Freshers
Why is Java a platform independent language?
Why is Java not a pure object oriented language?
Difference between Heap and Stack Memory in java. And how java utilizes this.
Can java be said to be the complete object-oriented programming language?
How is Java different from C++?
Pointers are used in C/ C++. Why does Java not make use of pointers?
What do you understand by an instance variable and a local variable?
What are the default values assigned to variables and instances in java?
What do you mean by data encapsulation?
Tell us something about JIT compiler.
Can you tell the difference between equals() method and equality operator (==) in Java?
How is an infinite loop declared in Java?
Briefly explain the concept of constructor overloading
Define Copy constructor in java.
Can the main method be Overloaded?
Comment on method overloading and overriding by citing relevant examples.
A single try block and multiple catch blocks can co-exist in a Java Program. Explain.
Explain the use of final keyword in variable, method and class.
Do final, finally and finalize keywords have the same function?
Is it possible that the ‘finally’ block will not be executed? If yes then list the case.
Identify the output of the java program and state the reason.
When can you use super keyword?
Can the static methods be overloaded?
Why is the main method static in Java?
Can the static methods be overridden?
Difference between static methods, static variables, and static classes in java.
What is the main objective of garbage collection?
What is a ClassLoader?
What part of memory – Stack or Heap – is cleaned in garbage collection process?
What are shallow copy and deep copy in java?
Java Intermediate Interview Questions
Apart from the security aspect, what are the reasons behind making strings immutable in Java?
What is a singleton class in Java? And How to implement a singleton class?
Which of the below generates a compile-time error? State the reason.
How would you differentiate between a String, StringBuffer, and a StringBuilder?
Using relevant properties highlight the differences between interfaces and abstract classes.
Is this program giving a compile-time error? If Yes then state the reason and number of errors it will give. If not then state the reason.
What is a Comparator in java?
In Java, static as well as private method overriding is possible. Comment on the statement.
What makes a HashSet different from a TreeSet?
Why is the character array preferred over string for storing confidential information?
What do we get in the JDK file?
What are the differences between JVM, JRE and JDK in Java?
What are the differences between HashMap and HashTable in Java?
What is the importance of reflection in Java?
What are the different ways of threads usage?
What are the different types of Thread Priorities in Java? And what is the default priority of a thread assigned by JVM?
What is the difference between the program and the process?
What is the difference between the ‘throw’ and ‘throws’ keyword in java?
What are the differences between constructor and method of a class in Java?
Identify the output of the below java program and Justify your answer.
Java works as “pass by value” or “pass by reference” phenomenon?
What is the ‘IS-A ‘ relationship in OOPs java?
Which among String or String Buffer should be preferred when there are lot of updates required to be done in the data?
How to not allow serialization of attributes of a class in Java?
What happens if the static modifier is not included in the main method signature in Java?
Consider the below program, identify the output, and also state the reason for that.
Can we make the main() thread a daemon thread?
What happens if there are multiple main methods inside one class in Java?
What do you understand by Object Cloning and how do you achieve it in Java?
How does an exception propagate in the code?
How do exceptions affect the program if it doesn’t handle them?
Is it mandatory for a catch block to be followed after a try block?
Will the finally block get executed when the return statement is written at the end of try block and catch block as shown below?
Can you call a constructor of a class inside the another constructor?
Contiguous memory locations are usually used for storing actual values in an array but not in ArrayList. Explain.
Why does the java array index start with 0?
Why is the remove method faster in the linked list than in an array?
How many overloaded add() and addAll() methods are available in the List interface? Describe the need and uses.
How does the size of ArrayList grow dynamically? And also state how it is implemented internally.
Java Interview Questions for Experienced
Although inheritance is a popular OOPs concept, it is less advantageous than composition. Explain.
What is the difference between ‘>>’ and ‘>>>’ operators in java?
What are Composition and Aggregation? State the difference.
How is the creation of a String using new() different from that of a literal?
How is the ‘new’ operator different from the ‘newInstance()’ operator in java?
Is exceeding the memory limit possible in a program despite having a garbage collector?
Why is synchronization necessary? Explain with the help of a relevant example.
In the given code below, what is the significance of … ?
What will be the output of the below java program and define the steps of Execution of the java program with the help of the below code?
Can you explain the Java thread lifecycle?
What could be the tradeoff between the usage of an unordered array versus the usage of an ordered array?
Is it possible to import the same class or package twice in Java and what happens to it during runtime?
In case a package has sub packages, will it suffice to import only the main package? e.g. Does importing of com.myMainPackage.* also import com.myMainPackage.mySubPackage.*?
Will the finally block be executed if the code System.exit(0) is written at the end of try block?
What do you understand by marker interfaces in Java?
Explain the term “Double Brace Initialisation” in Java?
Why is it said that the length() method of String class doesn’t return accurate results?
What is the output of the below code and why?
What are the possible ways of making object eligible for garbage collection (GC) in Java?
In the below Java Program, how many objects are eligible for garbage collection?
What is the best way to inject dependency? Also, state the reason.
How we can set the spring bean scope. And what supported scopes does it have?
What are the different categories of Java Design patterns?
What is a Memory Leak? Discuss some common causes of it.
Assume a thread has a lock on it, calling the sleep() method on that thread will release the lock?