Skip to content

Commit 881dac1

Browse files
authored
Update README.md
1 parent 8826c7d commit 881dac1

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,65 @@ public static void main(String[] args){//main thread starts here
225225
```
226226
---
227227

228+
### 11. Explain thread life cycle in Java
229+
230+
Thread has the following states:
231+
*New
232+
*Runnable
233+
*Running
234+
*Non-runnable (Blocked)
235+
*Terminated
236+
237+
![Thread Life Cycle](https://user-images.githubusercontent.com/649439/167628356-49e0a73f-d0d9-47ce-a643-5288e068a060.png)
238+
239+
240+
***New:** In New state, Thread instance has been created but start () method is not yet invoked. Now the thread is not considered alive.
241+
***Runnable:** The Thread is in runnable state after invocation of the start () method, but before the run () method is invoked. But a thread can also return to the runnable state from waiting/sleeping. In this state the thread is considered alive.
242+
***Running:** The thread is in running state after it calls the run () method. Now the thread begins the execution.
243+
***Non-Runnable(Blocked):** The thread is alive but it is not eligible to run. It is not in a runnable state but also, it will return to runnable state after some time. For Example: wait, sleep, block.
244+
***Terminated:** Once the run method is completed then it is terminated. Now the thread is not alive.
245+
246+
---
247+
248+
### 12. Which methods are used during the Serialization and Deserialization process?
249+
250+
ObjectOutputStream and ObjectInputStream classes are higher level java.io. package. We will use them with lower level classes FileOutputStream and FileInputStream.
251+
252+
ObjectOutputStream.writeObject —->Serialize the object and write the serialized object to a file.
253+
254+
ObjectInputStream.readObject —> Reads the file and deserializes the object.
255+
256+
To be serialized, an object must implement the serializable interface. If a superclass implements Serializable, then the subclass will automatically be serializable.
257+
258+
| Serialization | Deserialization |
259+
| ------------- |-------------|
260+
|Serialization is the process which is used to convert the objects into byte stream|Deserialization is the opposite process of serialization where we can get the objects back from the byte stream.|
261+
|An object is serialized by writing it an ObjectOutputStream.|An object is deserialized by reading it from an ObjectInputStream.|
262+
263+
---
264+
265+
### 13. When to use Runnable interface Vs Thread class in Java?
266+
267+
If we need our class to extend some other classes other than the thread then we can go with the runnable interface because in java we can extend only one class. If we are not going to extend any class then we can extend the thread class.
268+
269+
---
270+
271+
### 14. What is the life-cycle of a servlet?
272+
273+
There are 5 stages in the lifecycle of a servlet:
274+
275+
1. Servlet is loaded
276+
2. Servlet is instantiated
277+
3. Servlet is initialized
278+
4. Service the request
279+
5. Servlet is destroyed
280+
281+
![image](https://user-images.githubusercontent.com/649439/167629455-326556a3-d24c-4c28-88de-c16a40b946de.png)
282+
283+
---
284+
285+
### 15.
286+
287+
---
288+
228289
Wish you all the best.

0 commit comments

Comments
 (0)