30 Core Java Basic Interview Questions for Freshers

Last updated: September 2026 — merged two posts (10 + 20 questions) into one definitive 30-question list, refreshed with related reading.

This is the definitive list of core Java interview questions for freshers — 30 questions covering the fundamentals every Java beginner is expected to know. Answers are kept at fresher level: enough to answer confidently, with links to deeper tutorials where it matters.

Part 1: Java fundamentals (questions 1–10)

1. What is difference between Java and C++
Here we have listed only few differences.
  1. Java does not support pointers whereas C++ Support pointers.
  2. Java does not support destructors, it has automatic garbage collector, whereas C++ supports destructors.
  3. Java codes run in a JVM(Java Virtual Machine) whereas C++ codes runs on native executable machine.
  4. Java does not support operator overloading whereas C++ does.
  5. Java provides built in support for Thread whereas C++ does not provide built in support for Thread.
2. What is the difference between JDK and JRE
JDK (Java Development Kit) includes the JRE, compilers, JavaDoc, Java Debugger etc. The JDK is required to create and compile java programs. JRE (Java Runtime Environment) includes libraries, the Java Virtual Machine and other components to run Java programs — if you only need to run a Java application, the JRE is enough.

3. What is class in Java
A class is the blueprint from which individual objects are created — like an architect's blueprint for a house that can be reused to build many houses.

4. Can you write down the syntax of a simple Java program? (Hello World)
public class HelloWorld {
    public static void main(String...args) {
        System.out.println("Hello World !!!");
    }
}
5. What are the access modifiers in Java?
Four: default (no specifier), private, protected, public.

6. What is the difference between public, protected and private?
public — visible to all classes everywhere. protected — accessible within its own package and by subclasses in other packages. private — accessible only within its own class.

7. What happens if the main() method is declared as private?
The class compiles fine, but at runtime the JVM reports that the main method is not public (most IDEs won't even let you run it).

8. What happens if we remove static from the main() method signature?
It compiles, but at runtime you get a NoSuchMethodError because the JVM looks for the exact signature public static void main(String[]).

9. How to create an object in Java?
HelloWorld hello = new HelloWorld();
10. Which class is the parent of all classes in Java?
java.lang.Object — every class extends it, directly or indirectly.

Part 2: Classes, objects, and language basics (questions 11–30)

11. What is a constructor in Java and how do you create one?
A constructor is a special method named after the class, with no return type, used to initialize the object. It runs when you use the new operator — e.g. Book(){} for class Book.

12. What is the difference between a constructor and a method?
Constructors have no return type and must share the class name; they run once via new to create objects. Methods can have any name, declare a return type (or void), and operate on objects that already exist.

13. Can a constructor be called directly?
No — constructors are invoked only through the new operator (or via this(...)/super(...) chaining). Methods can be called directly.

14. What is method overloading?
Multiple methods with the same name but different parameter lists (type, number, or order). The compiler picks the matching signature at compile time.

15. What is method overriding?
A subclass redefines a method inherited from its parent with the same signature, providing its own implementation. Resolved at runtime (dynamic dispatch).

16. What is the difference between overloading and overriding?
Overloading: same name, different parameters, same class, compile-time. Overriding: same name and signature, subclass, runtime.

17. What is inheritance in Java?
A mechanism where a class (child) acquires the properties and behaviors of another class (parent) via extends. Java supports single inheritance for classes.

18. What is polymorphism?
"Many forms" — the same interface behaving differently per object. Compile-time (overloading) and runtime (overriding).

19. What is encapsulation?
Bundling data and the methods that operate on it into a single unit (class), hiding internals behind private fields and public getters/setters.

20. What is abstraction?
Hiding implementation complexity and exposing only the essential interface — via abstract classes and interfaces.

21. What is the difference between an abstract class and an interface?
An abstract class can have state, constructors, and concrete methods; a class extends only one. An interface (pre-Java 8) declares only method signatures; a class can implement many. Since Java 8, interfaces can carry default and static methods.

22. What is the static keyword used for?
For class-level members shared across all instances: static variables, static methods (callable without an object), static blocks (run once at class load).

23. What is the final keyword used for?
final variable — constant; final method — cannot be overridden; final class — cannot be extended (like String).

24. What is the difference between == and equals()?
== compares references (are they the same object?). equals() compares content — but only if the class overrides it (String does; your own classes must).

25. What is the super keyword?
Refers to the parent class: super() calls the parent constructor, super.method() calls a parent method shadowed by overriding.

26. What is the this keyword?
Refers to the current object — used to disambiguate fields from parameters (e.g. this.name = name) and to chain constructors via this(...).

27. Can you list the methods of the Object class?
toString(), equals(), hashCode(), getClass(), clone(), finalize(), wait(), notify(), notifyAll().

28. What is the transient keyword?
Marks a field to be skipped during serialization. Read the full transient tutorial.

29. What is a package in Java?
A namespace that organizes related classes and interfaces, and controls access via visibility rules.

30. Can you create an object of an abstract class?
No — abstract classes cannot be instantiated. You can only extend them and instantiate a concrete subclass.

Related reading

Comments

  1. Wow very nice collections of Java interview questions... please post more sir :)

    ReplyDelete
    Replies
    1. Glad to hear that you liked it. Sure will post few more question in our next series.

      Delete
  2. That is really useful piece of information, thanks for sharing it. Do keep sharing such good stuff.
    Core Java Courses

    ReplyDelete

Post a Comment

Popular posts from this blog

What are the core classes and interfaces of hibernate 4

JSP Servlet Interview Questions For Freshers Series 1

Java Banking Finance Services and Insurance (BFSI) domain interview questions