top 25 Java Interview Questions

1. What is Java?

Java is an object-oriented programming language based on the concepts of OOP(OBJECT ORIENTED PROGRAMMING LANGAUGE). It was developed by James Gosling and his team in 1991 at Sun Microsystems Corp. It was developed as part of a project to use technology in electronic gadgets.

2. What are the characteristics of Java?

Some of the characteristics of Java are:

  • Platform independent: It can run on any machine regardless of the operating system.
  • Object-oriented: Java is based on the object-oriented programming paradigm.
  • Secure: Java has built-in security features that help to protect applications from malicious code.
  • Robust: Java is a robust language that is designed to be free of errors.
  • Portable: Java code can be easily ported to other platforms.
  • Multithreaded: Java supports multithreading, which allows multiple tasks to be executed concurrently.
  • Dynamic: Java is a dynamic language, which means that the types of variables and expressions can be changed at runtime.

3. How does Java facilitate high performance?

Java facilitates high performance by using a Just-In-Time (JIT) compiler. The JIT compiler compiles Java bytecode into native machine code at runtime. This allows Java programs to run as fast as native programs.

4. What are the IDEs of Java?

Some of the popular IDEs for Java are:

  • Eclipse
  • IntelliJ IDEA
  • NetBeans
  • BlueJ
  • JCreator

5. What is Constructor?

A function or method having the same name, as class name is termed a constructor. The main objective of the constructor is to initialize the data members of the class. It has no return type. Even void keyword is not used. For e.g:

public class calculate{

int a, b;

calculate() // constructor


a=0; b=0;



6. Define Local and Instance variables.

Local variables are variables that are declared within a method or a block. Instance variables are variables that are declared within a class. instance variable depends on the life of the objects. It is created on the creation of the object and destroyed with the object destroy.

7. Describe a class.

A class is a blueprint for creating objects. A class defines the properties and methods of an object. It is a template for creating objects from the same class.

8. Define the Object.

An object is an instance of a class. An object is created by using the new keyword. It is an entity that has state and behaviour.

9. Can you list out the concepts in OOPs?

The four main concepts of OOPs are:

  • Abstraction: Abstraction is the process of hiding the implementation details and exposing only the essential details to the user.
  • Encapsulation: It refers to wrapping of data into a single unit called class and it is encapsulation.
  • Inheritance: Inheritance is the process of one class inheriting the properties and methods of another class.
  • Polymorphism: Polymorphism is a feature in which a function having the same name but different forms is called polymorphism. Function overloading is an example of polymorphism.

10. Define Inheritance.

Inheritance is the process of one class inheriting the properties and methods of another class. The class that inherits the properties and methods is called the derived class or subclass. The class that is being inherited from is called the base class or superclass.

11. What is the task of encapsulation?

Encapsulation is the process of combining data and methods into a single unit. This helps to protect the data from unauthorized access and modification.

12. Describe polymorphism.

Polymorphism is the ability of an object to take on different forms. This is achieved through inheritance and overriding.

13. What does Method Overriding entail?

Method overriding is a feature of OOPs that allows a subclass to have a method with the same name and signature as a method in its superclass. The subclass method inherits the property or features of the superclass or parent class method.

14. Explain Overloading in Java?

Overloading is a feature of OOPs that allows a class to have multiple methods with the same name but different signatures. The signatures of the methods must be different in terms of the number and/or type of the parameters.

15. What does “interface” mean?

It is a reference type of data type. It defines a set of methods but without body. It exhibits the behaviour of the class. For e.g

interface ABC




16. What does “Abstract class” mean?

It is a type of class whose objects cannot be created. It is declared with the abstract keyword. Abstract class can contain abstract and non-abstract methods

17. Define String, String Builder, and String Buffer.

String, StringBuilder, and StringBuffer are all classes that represent a sequence of characters. String is an immutable class, which means that once a String object is created, it cannot be changed. StringBuilder and StringBuffer are mutable classesthumb_upthumb_downuploadGoogle itmore_vert.

18. List down the difference between jdk, jre, jvm.

– JDK (Java Development Kit): It is a software development kit that includes the necessary tools to develop and compile Java applications.
– JRE (Java Runtime Environment): It provides the runtime environment for executing Java applications. It includes the JVM and necessary libraries.
– JVM (Java Virtual Machine): It is the virtual machine responsible for executing Java bytecode.

19. How static methods is different from non-static method?

Answer: Static methods belong to the class and can be called without creating an instance of the class. Non-static methods are associated with instances of the class and can access instance variables.

20. What is the difference between checked and unchecked exceptions?

– Checked exceptions: These are exceptions that need to be declared in the method signature using the `throws` keyword or handled within a try-catch block.
– Unchecked exceptions: These are exceptions that do not need to be declared or caught explicitly.

21. What is synchronization in Java?

Answer: Synchronization in Java ensures that only one thread can access a shared resource at a time, preventing concurrent modification and potential data inconsistency issues. It is achieved using the “synchronized” keyword or locks.

22. What is the difference between a stack and a heap?

– Stack: It is used to store local variables, method calls, and references to objects. It is thread-specific and has a limited size.
– Heap: It is used to store objects dynamically allocated using the “new” keyword. It is shared among multiple threads and has a larger size.

These answers should give you a good understanding of the concepts behind each question. However, make sure to adapt them to your own understanding and experience.

23. What do you understand by multithreading?

Answer: Multithreading is the concurrent execution of multiple threads within a single program. It allows for better utilization of CPU resources and enables handling multiple tasks simultaneously.

24. What is the difference between the “==” operator and the “equals()” method?

Answer: The “==” operator compares the references of objects, while the “equals()” method compares the contents of objects (the overridden implementation should be used for proper comparison).

25. What is the purpose of the “final” keyword in Java?

Answer: The “final” keyword can be used to declare a variable, method, or class. A final variable’s value cannot be changed, a final method cannot be overridden, and a final class cannot be inherited.