
Durgesh Tiwari
Author
Java interview questions on core concepts help developers prepare for technical interviews and improve programming knowledge.
These questions mainly cover important Java topics used in real-world applications and enterprise development.
In simple words: Core Java interview questions help developers understand important Java concepts commonly asked in interviews.
OOPs Concepts
Collections Framework
Exception Handling
Multithreading
JVM & Garbage Collection
String Handling
Java 8 Features
These topics are frequently asked in Java fresher interviews, backend developer interviews, and software engineering roles.
The four main pillars of Object-Oriented Programming are:
Encapsulation
Inheritance
Polymorphism
Abstraction
These concepts help developers build secure, reusable, and scalable applications.
Abstraction | Encapsulation |
|---|---|
Hides implementation details from the user | Hides internal data using access modifiers |
Focuses on what an object does | Focuses on how data is protected |
Achieved using abstract classes and interfaces | Achieved using classes, private variables, and getter/setter methods |
Improves code flexibility and design | Improves data security and control |
Example: ATM machine functionality | Example: Bank account balance protection |
Method overloading means creating multiple methods with the same name but different parameters.
void add(int a, int b)
void add(double a, double b)It supports compile-time polymorphism in Java.
Method overriding occurs when a subclass provides its own implementation of a parent class method.
It supports runtime polymorphism in Java.
These classes are used for handling text in Java, but they differ in mutability and thread safety.
Feature |
|
|
|
|---|---|---|---|
Nature | Immutable | Mutable | Mutable |
Performance | Slower for modifications | Faster | Slightly slower |
Synchronization | Automatically safe | Not synchronized | Synchronized |
Memory Usage | More object creation | Better memory efficiency | More overhead than |
Best Use Case | Fixed text data | Single-threaded applications | Multi-threaded applications |
Key Points
String objects cannot be modified after creation.
StringBuilder is faster and used in single-threaded applications.
StringBuffer is thread-safe and used in multi-threaded environments.
A String in Java is immutable, which means its value cannot be changed after creation.
Reasons
Improves security
Provides thread safety
Supports better memory management
Helps optimize the String Pool
String immutability improves Java performance, reliability, and application security.
ArrayList | LinkedList |
|---|---|
Uses dynamic array internally | Uses doubly linked list internally |
Faster in random access (get operation) | Slower in random access |
Slower insertion and deletion in middle | Faster insertion and deletion |
Better for read-heavy applications | Better for write-heavy applications |
Less memory usage | More memory usage due to node links |
HashMap | Hashtable |
|---|---|
Not synchronized | Synchronized (thread-safe) |
Faster performance | Slower due to synchronization |
Allows one null key and multiple null values | Does not allow null keys or values |
Introduced in Java 1.2 | Legacy class (older version) |
Preferred in modern applications | Rarely used in new projects |
Checked Exception | Unchecked Exception |
|---|---|
Checked at compile time | Occurs at runtime |
Must be handled using try-catch or throws | Not mandatory to handle |
Example: IOException, SQLException | Example: NullPointerException, ArrayIndexOutOfBoundsException |
Compiler forces handling | Compiler does not force handling |
Mostly related to external systems (files, DB) | Mostly programming mistakes |
The finally block in Java is a block that is executed after try-catch, regardless of whether an exception is thrown or not.
It is mainly used to ensure cleanup code always runs.
Key Points:
Executes every time after try-catch
Runs even if an exception occurs or not
Commonly used for resource cleanup
Synchronization is a mechanism used in Java to control access to shared resources in a multithreaded environment. It ensures that only one thread can access a critical section at a time, preventing data inconsistency and race conditions.
sleep() | wait() |
|---|---|
Belongs to Thread class | Belongs to Object class |
Does not release lock | Releases lock |
Used to pause execution for a fixed time | Used for inter-thread communication |
Does not require synchronization | Must be called inside synchronized context |
JVM (Java Virtual Machine) is a runtime environment that executes Java bytecode and provides platform independence by allowing Java programs to run on any operating system.
Garbage Collection is an automatic memory management process in Java that removes unused objects from memory.
It helps in efficient memory utilization and prevents memory leaks.
Lambda expressions provide a short and concise way to implement functional interfaces in Java.
Example:
(a, b) -> a + bThey are mainly used to write cleaner and more readable code, especially with collections and streams.
Stream API is used to process collections of data in a functional style.
It supports operations like filtering, mapping, and reducing data in a declarative way without modifying the original collection.
Reverse a string: Write a program to reverse a given string using loop or built-in methods.
Check palindrome: Verify whether a string or number reads the same forward and backward.
Fibonacci series: Generate a sequence where each number is the sum of the previous two numbers.
Find largest number in array: Iterate through an array to find the maximum element.
Remove duplicates from array: Eliminate repeated elements and return only unique values.
Focus on Java fundamentals such as OOP, exceptions, and multithreading
Practice coding regularly to improve problem-solving speed
Understand Java Collections Framework clearly with real examples
Build small mini projects to apply concepts practically
Practice debugging programs to improve logical thinking
Strong Core Java knowledge improves interview performance and coding confidence.