Basic Interview Questions on Multithreading in Java

Q 1 . What is the difference between Processes and Threads ?
Answer .

Processes are programs that are executing while threads are smallest unit of executable codes .
Processes are isolated from one another while threads share memory or resources with each other .
Q 2 . What are the ways of performing Multithreading in java ?
Answer . Multithreading in java can be performed in two different ways :
1. By extending Thread class .
2. by implementing Runnable Interface .
Q 3. What are the benefits of multi-threaded programming?
Answer . In multiple threading , multiple threads are executed concurrently that helps in improving the performance .
In MultiThreading , CPU is not idle when one thread is waiting for some resources .
Q 4 . Can we call run() method of a Thread class?
Answer . Yes , run() method can be called since it is a method of Thread class . But simply calling run method will make it behave as a normal method . run () method is executed using the start() method i.e Thread.start() .
Q 5 . How can we pause the execution of a Thread for specific time?
Answer . Execution of a Thread can be paused using sleep() method .
Syntax : Thread.sleep(timeMilliSec) .
timeMilliSec is the time in milliseconds for which we want to pause the execution of the thread.
Q 6 . What do you understand about Thread Priority ?
Answer . Thread priorities are numbers that specify relative priority of one thread in comparison to the other thread .
It is used to decide when to switch from one running thread to the other .
A simple program of multithreading in java( explaining each syntax ) is here : https://github.com/SaumyaSingh1/MultiThreading