Core Java Interview Questions and Answers


🔹 Section 1: Basic Java Questions

1. What is Java?

Java is a high-level, object-oriented programming language used for building applications like web, mobile, and enterprise software.


2. What are the features of Java?

  • Object-Oriented
  • Platform Independent
  • Secure
  • Robust
  • Multithreaded
  • Portable

3. Why is Java platform independent?

Because Java code is compiled into bytecode, which runs on the Java Virtual Machine (JVM).


4. What is JVM?

JVM (Java Virtual Machine) is responsible for running Java bytecode on any system.


5. Difference between JDK, JRE, and JVM?

TermMeaning
JDKJava Development Kit (tools for development)
JREJava Runtime Environment (runs Java programs)
JVMExecutes bytecode

🔹 Section 2: OOP Concepts

6. What is Object-Oriented Programming?

A programming style based on objects and classes.


7. What are the 4 pillars of OOP?

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction

8. What is Encapsulation?

Wrapping data and methods into a single unit (class).


9. What is Inheritance?

One class acquires properties of another class.


10. What is Polymorphism?

One action can behave in different ways.

Types:

  • Method Overloading
  • Method Overriding

11. What is Abstraction?

Hiding internal implementation and showing only functionality.


🔹 Section 3: Classes and Objects

12. What is a class?

A blueprint for creating objects.


13. What is an object?

An instance of a class.


14. Difference between class and object?

ClassObject
BlueprintReal entity
LogicalPhysical

🔹 Section 4: Constructors

15. What is a constructor?

A special method used to initialize objects.


16. Types of constructors:

  • Default constructor
  • Parameterized constructor

17. Can a constructor be overloaded?

Yes, constructors can be overloaded.


🔹 Section 5: Methods

18. What is a method?

A block of code that performs a specific task.


19. What is method overloading?

Same method name with different parameters.


20. What is method overriding?

Child class provides specific implementation of parent method.


🔹 Section 6: Strings

21. What is String in Java?

A sequence of characters.


22. Difference between String, StringBuffer, StringBuilder?

TypeMutable
StringNo
StringBufferYes (thread-safe)
StringBuilderYes (faster, not thread-safe)

23. Why String is immutable?

For security, performance, and memory optimization.


🔹 Section 7: Arrays

24. What is an array?

A collection of similar data types.


25. Types of arrays:

  • Single-dimensional
  • Multi-dimensional

🔹 Section 8: Exception Handling

26. What is an exception?

An error during program execution.


27. Types of exceptions:

  • Checked exceptions
  • Unchecked exceptions

28. Keywords used in exception handling:

  • try
  • catch
  • finally
  • throw
  • throws

29. What is finally block?

Block that always executes.


🔹 Section 9: Collections Framework

30. What is Collection Framework?

A set of classes and interfaces for storing and managing data.


31. Types of collections:

  • List
  • Set
  • Map
  • Queue

32. Difference between ArrayList and LinkedList?

ArrayListLinkedList
Faster accessFaster insertion/deletion
Uses arrayUses nodes

33. Difference between HashMap and HashTable?

HashMapHashTable
Not synchronizedSynchronized
Allows nullNo null allowed

🔹 Section 10: Multithreading

34. What is multithreading?

Running multiple threads simultaneously.


35. What is thread?

A lightweight process.


36. How to create a thread?

  • By extending Thread class
  • By implementing Runnable interface

37. What is synchronization?

It controls access of multiple threads to shared resources.


🔹 Section 11: Advanced Java Concepts

38. What is garbage collection?

Automatic memory management in Java.


39. What is serialization?

Converting object into byte stream.


40. What is deserialization?

Converting byte stream back into object.


41. What is interface?

A blueprint of a class containing abstract methods.


42. Difference between abstract class and interface?

Abstract ClassInterface
Can have methodsOnly abstract (before Java 8)
Supports constructorsNo constructors

🔹 Section 12: Real Interview Questions

43. Why Java is secure?

Because it does not use pointers and runs inside JVM.


44. Why main method is static?

So JVM can call it without creating an object.


45. Can we run Java without main method?

No (modern Java versions require main method).


46. What is difference between == and equals()?

==equals()
Compares referenceCompares content

47. What is final keyword?

Used to restrict:

  • variable (constant)
  • method (no override)
  • class (no inheritance)

48. What is static keyword?

Belongs to class, not object.


49. What is this keyword?

Refers to current class object.


50. What is super keyword?

Refers to parent class object.