JAVA TOP 25 (INTERVIEW-FOCUSED)
PART-1 ( – ) — CORE JAVA + OOPS FOUNDATION
Q Java kya hai?
Answer:
Java ek object-oriented, platform-independent language hai.
“Write Once, Run Anywhere” iska core idea hai.
JVM ki wajah se same code har OS pe chalta hai.
Enterprise, backend aur Android me heavy use hota hai.
Real-world:
Banking systems, large backend services
Q Java platform-independent kaise hai?
Answer:
Java code directly machine code me nahi jata.
Pehle bytecode banta hai.
Bytecode JVM pe run hota hai.
Har OS ka apna JVM hota hai.
Flow:
Java code → Bytecode → JVM → Machine
Q JDK, JRE aur JVM me difference
Answer:
JVM code execute karta hai.
JRE = JVM + libraries (run ke liye).
JDK = JRE + development tools.
Developer ko JDK chahiye.
Interview line:
Run → JRE, Develop → JDK
Q Java me OOPs concepts kaun-kaun se hain?
Answer:
Encapsulation, Inheritance, Polymorphism, Abstraction.
Java pure OOP nahi hai but mostly OOP hai.
Real-world modeling easy hoti hai.
Interviewer yahin se depth check karta hai.
Q Class aur Object me difference
Answer:
Class ek blueprint hoti hai.
Object us blueprint ka real instance hota hai.
Class se multiple objects ban sakte hain.
Memory object banne pe allocate hoti hai.
Example:
Class = Car
Object = BMW, Audi
Q main() method ka role kya hai?
Answer:
Program execution yahin se start hota hai.
JVM main() ko call karta hai.
static isliye hota hai kyunki object ki zarurat nahi.
Fixed signature mandatory hota hai.
Signature:
public static void main(String[] args)
Q Java me static keyword kya karta hai?
Answer:
static members class se belong karte hain.
Object create kiye bina access ho jaate hain.
Memory ek hi copy rakhti hai.
Utility methods me common hai.
Real-world:
[Link]()
JAVA TOP 25
PART-2 ( – ) — OOPS DEEP DIVE
Q Encapsulation kya hoti hai?
Answer:
Encapsulation ka matlab data ko private rakhna aur access methods ke through dena.
Ye data security aur control deta hai.
Java me private fields + getter/setter se achieve hoti hai.
Large projects me very important hai.
Example:
class User {
private int age;
Q Inheritance kya hota hai?
Answer:
Inheritance me ek class dusri class ke properties inherit karti hai.
Code reuse hota hai.
extends keyword use hota hai.
Java single inheritance support karta hai.
Example:
class A {}
class B extends A {}
Q Polymorphism kya hota hai?
Answer:
Same method name, different behavior.
Compile-time (overloading) aur runtime (overriding) hota hai.
Flexibility aur scalability deta hai.
Interview ka favourite concept hai.
Q Method Overloading kya hota hai?
Answer:
Same method name, different parameters.
Compile-time pe decide hota hai.
Return type se overloading nahi hoti.
Readability improve hoti hai.
Example:
add(int a, int b)
add(double a, double b)
Q Method Overriding kya hota hai?
Answer:
Child class parent ke method ko redefine karti hai.
Runtime pe decide hota hai.
Inheritance required hoti hai.
Dynamic binding ka example hai.
Q Abstraction kya hoti hai?
Answer:
Implementation hide karke sirf functionality dikhana.
abstract class aur interface se achieve hoti hai.
Loose coupling deta hai.
Large systems me must hai.
Q Abstract class vs Interface
Answer:
Abstract class methods + variables dono rakh sakti hai.
Interface sirf method signatures deta tha (Java 8 se default methods).
Multiple inheritance interface se possible hai.
Design decision pe depend karta hai.
JAVA TOP 25
PART-3 ( – ) — STRING, MEMORY, KEYWORDS
Q String Java me immutable kyun hoti hai?
Answer:
String immutable hoti hai matlab change nahi hoti.
Security, thread-safety aur performance ke liye aisa hai.
String pool memory reuse karta hai.
Agar change karo to nayi String banti hai.
Real-world:
Database passwords, URLs safe rehte hain.
Q String vs StringBuilder vs StringBuffer
Answer:
String immutable hoti hai.
StringBuilder mutable aur fast hota hai.
StringBuffer mutable aur thread-safe hota hai.
Single-thread → StringBuilder, Multi-thread → StringBuffer.
Q String Pool kya hota hai?
Answer:
String Pool JVM ka special memory area hai.
Same string literals ek hi memory share karte hain.
Memory optimization hoti hai.
new String() pool bypass karta hai.
Q == vs equals()
Answer:
== reference compare karta hai.
equals() content compare karta hai.
Strings ke liye hamesha equals() use karo.
Interview ka classic trap hai.
Q Java memory areas kaun-kaun se hote hain?
Answer:
Heap, Stack, Method Area, PC Register, Native Stack.
Objects heap me bante hain.
Local variables stack me hote hain.
GC heap clean karta hai.
Q final, finally, finalize()
Answer:
final variable/method/class ko restrict karta hai.
finally exception handling me hamesha chalta hai.
finalize() GC se pehle call hota tha (deprecated).
Naam similar, kaam alag.
Q Java me Garbage Collection kya hota hai?
Answer:
GC unused objects ko memory se hata deta hai.
Automatic memory management hoti hai.
Developer ko free nahi karna padta.
Performance improve hoti hai.
JAVA TOP 25
PART-4 ( – ) — COLLECTIONS, EXCEPTIONS, THREADS
Q Java Collections Framework kya hota hai?
Answer:
Collections Framework ek ready-made data structures ka set hai.
List, Set, Map iske main interfaces hain.
Data store aur manipulate karna easy hota hai.
Performance aur flexibility dono milti hai.
Real-world:
Users list, orders map, unique emails set
Q List, Set aur Map me difference
Answer:
List ordered hoti hai aur duplicates allow karti hai.
Set unordered hoti hai aur duplicates allow nahi karti.
Map key–value pair me data store karta hai.
Use-case pe depend karta hai kaunsa use karein.
Example:
• List → Shopping cart
• Set → Unique roll numbers
• Map → UserId → UserObject
Q Checked vs Unchecked Exception
Answer:
Checked exception compile-time pe check hoti hai.
Unchecked exception runtime pe aati hai.
Checked ko handle karna compulsory hota hai.
Unchecked mostly programming bugs hote hain.
Example:
Checked → IOException
Unchecked → NullPointerException
Q Multithreading kya hoti hai Java me?
Answer:
Multithreading me multiple threads ek saath run karte hain.
CPU utilization improve hota hai.
Concurrency handle hoti hai.
Java me Thread class aur Runnable interface use hota hai.
Real-world:
Web server multiple users ko handle karta hai.