JAVA
INTERVIEW
PREP
FRESH EDITION: 2025
Master the Core. Impress the Panel.
AMUTHAN S
LinkedIn Profile
Æ TOP 25 JAVA INTERVIEW QUESTIONS
Fresher Edition – 2025
Author: Amuthan S
Version: Free Preview
9 Welcome Note
Hello, future Java Developer!
This guide is created specially for freshers like you who are stepping into your first tech
interviews. I’ve handpicked 25 beginner-friendly Java questions — explained in simple language
to help you feel confident and sound smart during interviews.
This is a free sample, but a full version is coming soon with:
● 50+ real interview questions
● Behavioral (HR) questions
● Resume tips + Project templates
Let’s begin your journey with clarity and confidence
— Amuthan S
How to Use This Guide
● Read 3–4 questions every day
● Don’t just memorize — understand and practice
● Try to explain answers in your own words
● Bookmark this PDF — and come back before every interview
❓ Top 25 Java Interview Questions + Answers
1. What is Java and why is it popular?
Java is a high-level, object-oriented programming language developed by Sun
Microsystems (now owned by Oracle). It is designed to be platform-independent, meaning
code written once can run anywhere using the Java Virtual Machine (JVM).
' Key Features:
● Write Once, Run Anywhere – Thanks to the JVM
● Object-Oriented – Supports concepts like inheritance, polymorphism, encapsulation
● Automatic Memory Management – Handled by Garbage Collector
● Secure and Robust – Strong memory management and exception handling
✅software,
Java is widely used in web apps, mobile apps (Android), enterprise
and backend systems.
2. What is the JVM and what does it do?
JVM stands for Java Virtual Machine. It is the engine that runs Java bytecode.
' How it works:
1. Java source code (.java) is compiled into bytecode (.class files) using the Java
compiler.
2. JVM takes this bytecode and executes it on your machine, regardless of the operating
system.
' JVM Responsibilities:
● Loading and verifying bytecode
● Allocating memory
● Managing garbage collection
● Ensuring security
ºWindows,
JVM makes Java platform-independent, meaning the same code runs on
Mac, or Linux without changes.
3. What is the difference between JDK, JRE, and JVM?
Term Full Form Purpose
JDK Java Full package for developers (includes compiler,
Development debugger, JRE, etc.)
Kit
JRE Java Runtime Contains libraries and JVM to run Java programs
Environment
JVM Java Virtual Executes the Java bytecode
Machine
' Summary:
● JDK = JRE + Development Tools (used by programmers)
● JRE = JVM + Runtime Libraries (used to run programs)
● JVM = Core engine that runs bytecode
You write and compile code using JDK, but it runs on JVM through JRE.
4. What are the main features of Java?
Java has several strong features that make it a top choice for developers:
' Core Features:
● Platform Independent: Write once, run anywhere (JVM handles this)
● Object-Oriented: Everything is modeled using objects and classes
● Simple & Familiar: Syntax is clean and similar to C++
● Secure: Bytecode verification and no direct memory access
● Robust: Automatic garbage collection + exception handling
● Multithreaded: Can run multiple tasks simultaneously
● High Performance: Thanks to Just-In-Time (JIT) compiler
These features are why Java powers systems like banking, Android apps,
enterprise apps, and more.
5. What is a Class and Object in Java?
' Class:
● A class is a blueprint or template that defines properties (fields) and actions (methods).
● It does not consume memory until objects are created.
' Object:
● An object is an instance of a class.
● It represents a real-world entity and occupies memory.
✅ Example:
class Dog {
String name;
void bark() {
[Link]("Woof!");
}}
public class Main {
public static void main(String[] args) {
Dog d1 = new Dog(); // Object created
[Link] = "Rocky";
[Link](); // Output: Woof!
✅design.
Think of class as a car design, and object as a real car made from that
6. What is a Constructor in Java?
A constructor is a special method used to initialize objects.
' Key Points:
● It has the same name as the class
● It doesn’t have a return type
● It is automatically called when an object is created
' Types:
● Default Constructor (no parameters)
● Parameterized Constructor (with parameters)
Example:
class Student {
String name;
Student(String n) {
name = n;
}}
public class Test {
public static void main(String[] args) {
Student s1 = new Student("John");
[Link]([Link]); // Output: John
7. What is Method Overloading?
Method Overloading means having multiple methods with the same name but different
parameters in the same class.
' Why Use It?
● Increases code readability
● Useful when methods do similar actions with different data types
✅ Example
class MathUtils {
int add(int a, int b) {
return a + b;
double add(double a, double b) {
return a + b;
Overloading is compile-time polymorphism.
8. What is Method Overriding?
Method Overriding means redefining a method from the parent class in the child class.
' Rules:
● Method name, return type, and parameters must match
● Must be in inheritance (parent-child) relationship
● Use @Override annotation
✅ Example:
class Animal {
void sound() {
[Link]("Animal sound");
class Dog extends Animal {
@Override
void sound() {
[Link]("Dog barks");
î Overriding is runtime polymorphism
9. What is Inheritance in Java?
Inheritance allows one class (child) to inherit properties and methods from another class
(parent).
' Syntax:
class Parent {
void show() {
[Link]("Parent class");
class Child extends Parent {
void display() {
[Link]("Child class");
' Types of Inheritance:
● Single
● Multilevel
● Hierarchical (Java doesn't support multiple inheritance via class)
✅ Promotes code reuse
10. What is Polymorphism in Java?
Polymorphism means "many forms". In Java, it allows one action to behave differently in
different situations.
' Types:
● Compile-time Polymorphism (Method Overloading)
● Runtime Polymorphism (Method Overriding)
✅ Example of Runtime Polymorphism:
class Animal {
void sound() {
[Link]("Animal makes a sound");
class Cat extends Animal {
void sound() {
[Link]("Cat meows");
public class Test {
public static void main(String[] args) {
Animal a = new Cat(); // Polymorphism
[Link](); // Output: Cat meows
º Polymorphism improves flexibility and reusability of code.
11. What is Encapsulation in Java?
Encapsulation means hiding internal details and only exposing what is necessary.
' How to Achieve:
● Declare variables as private
● Provide public getter and setter methods to access them
✅ Example:
class Employee {
private String name; // hidden from outside
public void setName(String n) {
name = n;
public String getName() {
return name;
ý Encapsulation improves data security, code readability, and maintainability.
12. What is Abstraction in Java?
Abstraction means hiding the implementation details and showing only essential features.
' Achieved By:
● Abstract classes
● Interfaces
✅ Example with Interface:
interface Vehicle {
void start();
class Car implements Vehicle {
public void start() {
[Link]("Car starts");
Abstraction helps in building flexible and scalable code.
13. What is the difference between ‘==’ and .equals()?
Operator Use Checks
== Comparison Compares memory addresses (reference)
operator
.equals() Method Compares actual content of two objects (in String,
etc.)
✅ Example:
String a = new String("Java");
String b = new String("Java");
[Link](a == b); // false (different objects)
[Link]([Link](b)); // true (same content)
❗ This is a common question that tests understanding of object vs reference.
14. What are access modifiers in Java?
Access modifiers control the visibility of classes, variables, and methods.
Modifier Visibility
public Visible everywhere
private Visible only inside the class
protected Visible within package + subclasses
default Visible within the same package only
Example:
public class Car {
private String model; // private - not accessible outside directly
! Access modifiers help enforce encapsulation and security.
15. What is a Static keyword in Java?
static is a keyword used for class-level members that don’t belong to objects.
' Used with:
● Variables (shared by all objects)
● Methods (can be called without object)
● Blocks and nested classes
✅ Example:
class Counter {
static int count = 0;
Counter() {
count++;
[Link](count);
static members belong to the class itself, not any object.
16. What is the final keyword in Java?
final is used to declare something unchangeable.
' Uses:
● final variable: value cannot be changed
● final method: cannot be overridden
● final class: cannot be inherited
✅ Example:
final int x = 10;
// x = 20; // Error
final class Animal { }
// class Dog extends Animal { } // Error
ñ final ensures constant behavior and security.
17. What is a Package in Java?
A package is a group of related classes and interfaces.
' Types:
● Built-in: [Link], [Link]
● User-defined: You can create your own package
How to create and use:
package myapp;
public class Hello {
public void sayHi() {
[Link]("Hi!");
Ô Packages help in organizing code, avoiding name conflicts, and improving
modularity.
18. What is an Interface in Java?
An interface is a contract that defines method signatures without implementing them. A class
that implements an interface must provide the method bodies.
' Key Points:
● All methods in interfaces are public and abstract (by default)
● Interfaces support multiple inheritance
● From Java 8, interfaces can have default and static methods
✅ Example:
interface Shape {
void draw();
class Circle implements Shape {
public void draw() {
[Link]("Drawing Circle");
Use interfaces when you want to define shared behavior across unrelated
classes.
19. What is the difference between Abstract Class and Interface?
Feature Abstract Class Interface
Methods Can have both abstract and Only abstract methods (until
concrete methods Java 7)
Constructors Can have constructors Cannot have constructors
Multiple Inheritance Not supported Supported
Access Modifiers Can have any All methods are public by
default
✅ Use abstract class when you want to provide default behavior. Use interface
for defining a common API.
20. What is Exception Handling in Java?
Exception Handling is Java’s mechanism to handle errors (exceptions) during runtime without
crashing the program.
' Common Keywords:
● try – Wraps code that may cause exception
● catch – Handles the exception
● finally – Executes regardless of exception
● throw – Used to throw an exception
● throws – Declares exceptions a method can throw
✅ Example:
try {
int x = 5 / 0;
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
Proper exception handling makes your app robust and user-friendly.
21. What is the difference between Checked and Unchecked Exceptions?
Type Checked Exception Unchecked Exception
Checked at Compile-time Runtime
Example IOException, SQLException NullPointerException,
ArithmeticException
Handling Must be handled with try-catch or Optional
throws
ú Knowing when and how to handle each type is crucial for writing resilient code.
22. What is Multithreading in Java?
Multithreading allows multiple tasks (threads) to run simultaneously in a program.
' Benefits:
● Better CPU utilization
● Faster program execution
' How to implement:
1. Extend Thread class
2. Implement Runnable interface
✅ Example:
class MyThread extends Thread {
public void run() {
[Link]("Thread is running");
⚙ Multithreading is used in games, servers, real-time apps, etc.
23. What is the Collection Framework in Java?
The Collection Framework provides a set of interfaces and classes to store and manipulate
groups of objects.
' Key Interfaces:
● List – Ordered, allows duplicates (e.g. ArrayList)
● Set – No duplicates (e.g. HashSet)
● Map – Key-value pairs (e.g. HashMap)
✅ Example:
List<String> names = new ArrayList<>();
[Link]("John");
È Collections make it easy to organize and work with data in Java.
24. Difference between Array and ArrayList
Feature Array ArrayList
Size Fixed Dynamic
Type Can store primitive types Only objects
Performance Slightly faster More flexible
Features No built-in methods Many utility methods (e.g. .add(),
.remove())
Example:
int[] arr = new int[5]; // Array
ArrayList<Integer> list = new ArrayList<>(); // ArrayList
⚖ Use Array when size is known, ArrayList when size may vary.
25. What is Garbage Collection in Java?
Garbage Collection (GC) is the process of automatically freeing memory by removing
unused objects.
' How it works:
● JVM keeps checking for objects with no references
● When found, those objects are automatically removed from memory
✅ Example:
Car c = new Car();
c = null; // Now eligible for garbage collection
' Triggering GC manually (not recommended):
[Link](); // Requests JVM to run GC
♻ Garbage Collection improves performance by preventing memory leaks.
Æ What’s Next?
~ Congrats on completing this free sample!
You’ve just scratched the surface of what Java interviews expect.
Want to crack your next interview with full confidence?
7 The Full Interview Kit is coming soon:
● 50+ Technical Q&A
● HR Round Questions
● Java Project Template (with code)
● Resume Format + Tips
✅
Be the first to grab it at ₹99!
No fluff, only real prep
Instagram: @freakenamudhan