DEV Community

Quipoin
Quipoin

Posted on

5 Most Asked Java Interview Questions (With Answers)

  1. What is the difference between JDK, JRE, and JVM?

Answer:

JVM (Java Virtual Machine):
JVM is responsible for running Java bytecode and converting it into machine code so programs can execute on any system.

JRE (Java Runtime Environment):
JRE provides the environment required to run Java programs. It includes JVM + libraries.

JDK (Java Development Kit):
JDK is used for developing Java applications. It includes JRE + development tools like compiler (javac).

πŸ‘‰ In short:
JDK β†’ For Development
JRE β†’ For Running Java
JVM β†’ Executes Java bytecode.

  1. What are the main OOP concepts in Java?

Answer:

Java is based on Object-Oriented Programming. The four main principles are:

  • Encapsulation – Wrapping data and methods together in a class.
  • Inheritance – One class can acquire properties of another class.
  • Polymorphism – One method behaves differently in different situations.
  • Abstraction – Hiding implementation details and showing only functionality.

These concepts help in writing reusable, scalable, and maintainable code.

  1. Why is Java Platform Independent?

Answer:

Java is platform independent because Java code is compiled into bytecode, which can run on any system that has a JVM installed.

Flow:
Java Code β†’ Bytecode β†’ JVM β†’ Machine Code

That’s why Java follows the concept:
"Write Once, Run Anywhere."

  1. What is the difference between == and .equals() in Java?

Answer:

==

Compares memory addresses (reference comparison).

.equals()

Compares actual content or values of objects.

Example:

String a = new String("Java");
String b = new String("Java");

System.out.println(a == b); // false
System.out.println(a.equals(b)); // true

In interviews, this question checks your understanding of object comparison.

  1. What is Exception Handling in Java?

Answer:

Exception Handling is a mechanism used to handle runtime errors so that the program does not crash.

It uses:

  • try
  • catch
  • finally
  • throw
  • throws

Example:

try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: Cannot divide by zero");
}

Java has two types of exceptions:

Checked Exceptions

Unchecked Exceptions.

Call To Action (CTA)

If you want to learn Java from beginner to advanced, including exercises, interview questions, and MCQs:

πŸ‘‰ https://www.quipoin.com/tutorial/java

Start building your Java developer career today πŸš€

Top comments (0)