☕ Java
Intermediate
What is a thread in Java?
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.
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?