Search Interview Questions
| More than 3000 questions in repository.|
There are more than 900 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Java - Interview Questions and Answers|
|Frequently asked to fresh graduates.|
|Ans. 1. when an OS wants to start running program it creates new process means a process is a program that is currently executing and every process has at least one thread running within it.|
2). A thread is a path of code execution in the program, which has its own local variables, program counter(pointer to current execution being executed) and lifetime.
3. When the JavaVirtual Machine (JavaVM, or just VM) is started by the operating system, a new process is created. Within that process, many threads can be created.
4. Consider an example : when you open Microsoft word in your OS and you check your task manger then you can see this running program as a process. now when you write something in opened word document, then it performs more than one work at same time like it checks for the correct spelling, it formats the word you enter , so within that process ( word) , due to different path execution(thread) all different works are done at same time.
5. Within a process , every thread has independent path of execution but there may be situation where two threads can interfere with each other then concurrency and deadlock come is picture.
6. like two process can communicate ( ex:u open an word document and file explorer and on word document you drag and drop another another file from file explorer), same way two threads can also communicate with each other and communication with two threads is relatively low.
7. Every thread in java is created and controlled by unique object of java.lang.Thread class.
8. prior to jdk 1.5, there were lack in support of asynchronous programming in java, so in that case it was considered that thread makes the runtime environment asynchronous and allow different task to perform concurrently.
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve  java   operating system   threads   processes Asked in 2 Companies   frequent|
| Which keyword is used to provide explicit access of a code block to single thread ? |
|Explain multithreading in Java ?|
|What is the difference between time slicing and preemptive scheduling ?|
|What is a Deadlock ?|
|Explain Thread States ?|
|Why do we need Thread class even in case we execute thread using runnable interface ?|
|What is an object's lock and which object's have locks?|
|Different ways of implementing Threads in Java ?|
|Difference between Process and Thread ?|
|What is race condition ?|