What is a thread in Java?
Why Interviewers Ask This
Mid-level Java roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
A thread is the smallest unit of execution within a program. Java is multi-threaded, meaning multiple threads can run concurrently within the same process, sharing the same heap memory but each having its own stack. Create threads by either extending Thread class and overriding run(), or implementing the Runnable interface and passing it to a Thread: new Thread(runnable).start(). Call start() (not run()) to begin execution in a new thread — calling run() directly executes it on the current thread. Thread states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Java candidates.
More Java Questions
View all →- Intermediate What is the Java Collections Framework?
- Intermediate What is the difference between ArrayList and LinkedList?
- Intermediate What is HashMap in Java and how does it work internally?
- Intermediate What is the difference between HashMap and HashTable in Java?
- Intermediate What is the difference between HashMap and LinkedHashMap?