2017  Kodetalk | Feedback | Privacy Policy | Terms | About

What is the difference between processes and threads in Java?

I got this as interview question, Not sure what to answer for this question?


Basically a process is an execution of a program where a thread is a single execution sequence within the process. A process can contain multiple threads. A thread is sometimes called a lightweight process.


A JVM runs in a single process and threads in a JVM share the heap belonging to that process. That is why several threads may access the same object. Threads share the heap and have their own stack space. This is how one thread's invocation of a method and its local variables are kept thread safe from other threads.

Answer is