Table of Contents
Toggle75 Java Interview Questions & Answers for Freshers
Beginner Level
1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language used for developing desktop, web, and mobile applications.
Reason: Java uses JVM (Java Virtual Machine) which makes it platform independent.
2. What are the features of Java?
Main features:
Object-Oriented
Platform Independent
Simple
Secure
Robust
Multithreaded
High Performance
3. What is JVM?
JVM (Java Virtual Machine) executes Java bytecode and makes Java platform independent.
4. What is JDK?
JDK (Java Development Kit) includes JRE, compiler, debugger, and tools for Java development.
5. What is JRE?
JRE (Java Runtime Environment) contains libraries and JVM required to run Java programs.
6. What is bytecode in Java?
Bytecode is the intermediate code generated after compilation. JVM executes it.
7. What is a class in Java?
A class is a blueprint or template that defines properties and behavior.
8. What is an object?
An object is an instance of a class containing state and behavior.
9. What is the main() method?
Entry point of a Java program.public static void main(String[] args)
10. What is a variable?
A variable is a container that stores data.
11. What are data types?
Two types:
Primitive (int, float, boolean, char, byte, short, long, double)
Non-Primitive (String, Arrays, Class)
12. What is the difference between == and equals()?
==compares memory addressesequals()compares values
13. What is a constructor?
A special method used to initialize objects.
14. Types of constructors?
Default
Parameterized
15. What is method overloading?
Multiple methods with the same name but different parameters.
16. What is method overriding?
Subclass provides a specific implementation of a method already defined in parent class.
17. What is inheritance?
Mechanism where one class acquires properties of another.
18. Types of inheritance in Java?
Single
Multilevel
Hierarchical
(Java does not support multiple inheritance using classes)
19. What is polymorphism?
Ability to take many forms (overloading + overriding).
20. What is encapsulation?
Wrapping data and methods together using private variables + getters/setters.
21. What is abstraction?
Hiding internal details and showing only essential features.
Using abstract classes and interfaces.
22. What is an interface?
A blueprint containing abstract methods and static/final variables.
23. What is a package?
A package groups related classes to avoid naming conflicts.
24. What is “this” keyword?
Refers to the current object instance.
25. What is “super” keyword?
Refers to parent class methods/variables.
Intermediate Level
26. Difference between ArrayList and LinkedList
| Feature | ArrayList | LinkedList |
|---|---|---|
| Storage | Dynamic array | Doubly linked list |
| Best for | Retrieval | Insertion/Deletion |
| Speed | Faster for get() | Faster for add()/remove() |
27. What is a constructor chaining?
Calling one constructor from another using this() or super().
28. What is String Pool?
A special memory area in JVM where String literals are stored to save memory.
29. Why are Strings immutable?
For security, caching, performance, and thread safety.
30. Difference between String, StringBuilder, StringBuffer
String – immutable
StringBuilder – mutable, fast, not thread-safe
StringBuffer – mutable, slow, thread-safe
31. What is exception handling?
Mechanism to handle runtime errors using:try, catch, finally, throw, throws
32. Types of exceptions?
Checked
Unchecked
Errors
33. What is finally block?
Executes regardless of exception (used for closing resources).
34. What is a Thread?
A lightweight process used in multitasking.
35. Ways to create a thread?
Extending
ThreadclassImplementing
Runnable
36. What is synchronization?
Prevents multiple threads from accessing a shared resource simultaneously.
37. What is a static keyword used for?
Used for memory management; static members belong to the class, not objects.
38. What is a Singleton class?
A class that allows only one instance.
39. What is an abstract class?
A class with abstract and non-abstract methods.
40. What is marker interface?
Interface without methods (e.g., Serializable).
41. What is final keyword?
Used to make:
variable → constant
method → cannot override
class → cannot inherit
42. What is a wrapper class?
Object representation of primitive data types.
Example: Integer, Boolean, Double.
43. What is autoboxing and unboxing?
Autoboxing: primitive → wrapper
Unboxing: wrapper → primitive
44. What is garbage collection?
Automatic memory cleanup done by JVM.
45. What is Collections Framework?
Set of classes and interfaces for data storage.
Examples: List, Set, Map.
Advanced Level
51. What is JVM architecture?
Consists of:
Class Loader
Memory Area
Execution Engine
Native Interface
52. Explain Class Loader.
Loads class files into memory.
Phases:
Loading
Linking
Initialization
53. What is a Class Loader Subsystem?
Loads classes dynamically during runtime.
54. What is JIT compiler?
JIT compiles bytecode into native machine code for faster performance.
55. What is Multithreading?
Executing multiple threads simultaneously for faster processing.
56. What is a Deadlock?
Situation where two threads wait for each other’s resources.
57. What is volatile keyword?
Ensures variable visibility across threads.
58. What is transient keyword?
Used to skip serialization of a variable.
59. What is Java Memory Model?
Specifies interaction between threads and memory (Heap + Stack).
60. What are Lambdas? (Java 8)
Anonymous functions used to write cleaner code.
Example:() -> System.out.println("Hello");
61. What is a Stream API?
Used to process collections using functional methods like filter(), map(), reduce().
62. What is Optional class?
Avoids NullPointerException by representing optional values.
63. What is Functional Interface?
An interface with exactly one abstract method.
Example: Runnable.
64. What is the difference between Parallel Stream and Stream?
Stream → sequential
Parallel stream → multi-threaded execution
65. What is Reflection API?
Allows inspecting and modifying classes at runtime.
66. What is an Annotation?
Metadata for classes, methods, variables.
Example: @Override
67. What is a Microservice in Java?
Small, independent services built using Spring Boot.
68. What is Dependency Injection?
Technique where objects are provided rather than created.
69. What is JDBC?
Java Database Connectivity used to interact with databases.
70. Explain JDBC steps.
Load Driver
Create Connection
Create Statement
Execute Query
Close Connection
71. What is Hibernate?
An ORM tool used for database mapping in Java.
72. What is Spring Framework?
Enterprise-level framework used for building Java applications.
73. What is REST API?
Web service that uses HTTP methods (GET, POST, PUT, DELETE).
74. Difference between GET and POST
GET → fetch data
POST → send data
75. Explain the concept of Serialization
Process of converting an object into a byte stream for storage or transfer.
