1. What is Multithreading in Java?
Multithreading means executing two or more parts of a program (threads) simultaneously
to make efficient use of CPU. Each thread runs independently.
Example:
class MyThread extends Thread { public void
run(){[Link]('Running...');} public static void
main(String args[]){MyThread t=new MyThread();[Link]();}}
Hindi: Multithreading ka matlab hota hai ek hi program ke multiple parts (threads) ko ek
saath chalana, taaki CPU ka pura use ho sake.
2. Difference between Process and Thread?
Process is an independent program in execution; a thread is a lightweight subpart of a
process.
Threads share memory of process; processes have separate memory.
Hindi: Process ek independent program hota hai, jabki thread ek chhota part hota hai
process ka.
3. What is Thread Lifecycle?
States: New → Runnable → Running → Waiting/Sleeping → Terminated.
Hindi: Thread ka lifecycle 5 stages mein hota hai: New, Runnable, Running, Waiting, aur
Terminated.
4. Difference between start() and run()?
start() - creates a new thread and calls run() internally.
run() - executed like a normal method in same thread.
Hindi: start() ek naya thread banata hai, jabki run() sirf method ko call karta hai bina naya
thread banaye.
5. How to create a thread in Java?
Two ways:
1. By extending Thread class.
2. By implementing Runnable interface.
Hindi: Thread banane ke 2 tareeke hote hain — Thread class extend karke ya Runnable
interface implement karke.
6. What is synchronization?
Synchronization ensures only one thread can access a shared resource at a time to avoid
conflicts.
Hindi: Synchronization ek mechanism hai jisse ek time par sirf ek thread shared resource
use kar sakta hai.
7. Example of synchronized block?
synchronized(this){ [Link]('Thread safe block'); }
Hindi: synchronized block use karke hum specific part ko thread-safe bana sakte hain.
8. What is [Link]()?
It pauses current thread for given milliseconds.
Hindi: [Link]() current thread ko kuch time ke liye rok deta hai.
9. What is join() in thread?
join() waits for one thread to finish before the next starts.
Hindi: join() use hota hai ek thread ke complete hone ka wait karne ke liye.
10. What is yield()?
It temporarily pauses the current thread to give chance to others.
Hindi: yield() current thread ko thoda time ke liye rok kar doosre threads ko chalne ka
mauka deta hai.
11. What is thread priority?
Each thread has a priority (1–10). Higher priority threads get more CPU time.
Hindi: Har thread ki ek priority hoti hai, jisse decide hota hai kaunsa thread pehle chalega.
12. Default thread priority?
Default is 5 (Normal priority).
Hindi: Default priority 5 hoti hai.
13. What is daemon thread?
Daemon thread runs in background (like Garbage Collector). Ends when all user threads
finish.
Hindi: Daemon threads background mein chalte hain aur jab saare user threads khatam
ho jaate hain, ye bhi band ho jaate hain.
14. How to make a thread daemon?
[Link](true); (before start())
Hindi: setDaemon(true) call karke thread ko daemon banate hain.
15. What is thread safety?
When code behaves correctly even when accessed by multiple threads at once.
Hindi: Jab multiple threads ek saath kaam karte hue code ko galat output nahi dete, tab
code thread-safe hota hai.
16. What is deadlock?
When two or more threads wait forever for each other’s locked resources.
Hindi: Jab do threads ek dusre ke resource ke liye wait karte rehte hain bina release kiye,
use deadlock kehte hain.
17. Example of deadlock?
synchronized(obj1){ synchronized(obj2){}} and another thread in reverse
order.
Hindi: Agar ek thread obj1 lock kare aur dusra obj2, aur dono ek dusre ke lock ka wait
karein, to deadlock hota hai.
18. What is wait(), notify(), notifyAll()?
Used for inter-thread communication.
wait() – thread waits.
notify() – wakes one waiting thread.
notifyAll() – wakes all waiting threads.
Hindi: Ye methods threads ke beech coordination ke liye use hote hain.
19. Difference between sleep() and wait()?
sleep() doesn't release lock; wait() releases lock.
Hindi: sleep() lock release nahi karta, par wait() karta hai.
20. Can we call start() twice?
No, it throws IllegalThreadStateException.
Hindi: start() sirf ek baar call kar sakte hain.
21. Can we restart a dead thread?
No, once dead cannot be restarted.
Hindi: Ek baar dead thread dobara start nahi hota.
22. What is ReentrantLock?
A class in [Link] that gives more control than synchronized.
Hindi: ReentrantLock ek advanced locking mechanism hai jo synchronized se zyada
control deta hai.
23. What is Executor framework?
Part of [Link] – manages thread pools automatically.
Hindi: Executor framework threads ka group manage karta hai automatically.
24. What is Callable interface?
Similar to Runnable but can return a value and throw exception.
Hindi: Callable Runnable jaisa hi hai, par ye value return kar sakta hai.
25. Difference between Runnable and Callable?
Runnable → no return value.
Callable → returns value.
Hindi: Runnable kuch return nahi karta, Callable result return karta hai.
26. What is Future in Java?
Represents result of an asynchronous computation.
Hindi: Future ek object hai jisme background thread ka result store hota hai.
27. What is ThreadGroup?
A way to group multiple threads for easier control.
Hindi: ThreadGroup threads ka ek group hota hai jise manage karna easy hota hai.
28. What is volatile keyword?
Makes variable value always read from main memory, not cache.
Hindi: volatile ensure karta hai ki variable ka latest value main memory se hi read ho.
29. What is atomic operation?
An operation performed completely without interference.
Hindi: Atomic operation wo hota hai jo poora ek hi step mein complete ho jaata hai.
30. Why use multithreading?
For faster execution, better performance, and efficient CPU use.
Hindi: Multithreading se program fast chalta hai aur CPU ka full use hota hai.