Skip to content

Commit 9a4fca6

Browse files
committed
Fixed and Align proper.
Signed-off-by: Someshdiwan <[email protected]>
1 parent 99c6e92 commit 9a4fca6

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

site/Explaination.md

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ c = 1111 1110
248248
- x \| x = x
249249
---
250250
- Swapping two values without a temporary variable
251-
```
251+
252+
```
252253
You can swap the values of two integers using XOR without an extra temporary variable.
253254
254255
For example, suppose: // E.g. a = 2 (0b0010), b = 5 (0b0101)
@@ -301,6 +302,7 @@ try (FileReader fr = new FileReader(filepath)) {
301302
- Must be a child of `Throwable`
302303
- If checked exception, must extend `Exception`
303304
- If unchecked exception, must extend `RuntimeException`
305+
304306
---
305307

306308
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
@@ -477,9 +479,10 @@ class Boy extends Human {
477479
Note that, as detailed in the [Polymorphism](#polymorphism) section, the binding of *overloaded* methods is static,
478480
while the binding of *overridden* methods is dynamic.
479481

482+
---
483+
480484
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
481485

482-
---
483486

484487
## Interfaces
485488
An interface may have abstract methods, default methods, static methods, constants, and nested types.
@@ -505,16 +508,18 @@ Interfaces and their methods are implicitly `abstract`. Their methods are implic
505508
The most common use of extending interfaces occurs when the parent interface doesn't have any methods.
506509
Example:
507510
The MouseListener interface in `java.awt.event` extends `java.util.EventListener`, which is defined as follows:
511+
508512
```java
509513
package java.util;
510514
public interface EventListener {}
511515
```
512-
Thus, an interface with no methods is a **tagging interface**.
513-
These have two basic design purposes:
516+
517+
Thus,an interface with no methods is a **tagging interface**. These have two basic design purposes:
514518
1. Creates a common parent
515519
2. Adds a data type to a class. A class that implements a tagging interface becomes an interface type through polymorphism
516520

517521
---
522+
518523
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
519524

520525
## Nested Classes
@@ -535,6 +540,7 @@ classes inner classes inner classes
535540
This means a class cannot inherit multiple classes. However, a class **can** implement multiple interfaces.
536541

537542
---
543+
538544
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
539545

540546
## Java Generics
@@ -564,6 +570,7 @@ public class Box<T> {
564570
}
565571
```
566572
---
573+
567574
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
568575

569576
## Serialization
@@ -607,7 +614,7 @@ The return value of `readObject()` should be cast to the proper class.
607614
<sup><sub>[▲ TOP](#table-of-contents)</sub></sup>
608615

609616

610-
## Multithreading
617+
## Multithreading 🧵
611618
Lifecycle of a thread:
612619
- **New:** a new thread begins in this state where it remains until the program starts the thread
613620
- **Runnable:** executing its task
@@ -617,19 +624,43 @@ Lifecycle of a thread:
617624

618625
Thread priorities range from `MIN_PRIORITY` (a constant of 1) to `MAX_PRIORITY` (a constant of 10).
619626

627+
628+
---
629+
630+
### 🧵 Ways to Create a Thread in Java
631+
620632
There are two ways of creating a thread:
621-
1. Implement the `Runnable` interface
622-
- If you want a class to be executed as a thread, it must implement `Runnable`. This method takes three basic steps:
623-
1. Implement a `run()` method
624-
2. Instantiate a `Thread` object, like so: `Thread (Runnable threadObj, String threadName)`, where threadObj is an instance of a class that implements `Runnable`, and threadName is the name given to the new thread
625-
3. Start a Thread object with `start()`, which executes a class to the class's `run()` method
626-
627-
2. Extend the `Thread` class
628-
- This approach provides more flexibility in handling multiple threads created using available methods in the `Thread` class.
629-
1. Override the `run()` method in `Thread` class
630-
2. After creating the `Thread` object, start it with the `start()` method
631-
632-
### Thread Synchronization
633+
634+
#### 1. Implement the `Runnable` interface
635+
636+
If you want a class to be executed as a thread, it must implement `Runnable`.
637+
638+
This method involves three basic steps:
639+
640+
1. Implement a `run()` method.
641+
642+
2. Instantiate a `Thread` object like so:
643+
```java
644+
Thread(Runnable threadObj, String threadName);
645+
```
646+
where `threadObj` is an instance of a class that implements `Runnable`, and `threadName` is the name given to the
647+
new thread.
648+
649+
3. Start the thread with `start()`, which calls the class's `run()` method
650+
651+
---
652+
653+
#### 2. Extend the `Thread` class.
654+
655+
This approach provides more flexibility in handling multiple threads using available methods in the `Thread` class.
656+
657+
1. Override the `run()` method in your class that extends `Thread`.
658+
2. After creating the `Thread` object, start it with the `start()` method.
659+
660+
---
661+
662+
### Thread Synchronization:
663+
633664
What if two threads try to access the same resources? For example, if multiple threads try to write to the same
634665
file at the same time, they could corrupt the file.
635666

@@ -858,7 +889,7 @@ tmp.demoMethod();
858889
```
859890

860891
you can use the [Collections.synchronizedList](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#synchronizedList-java.util.List-)
861-
function to create a synchronized list, thus getting you the equivalent of a `Vector`.
892+
function to create a synchronized list, thus getting you the equivalent of a Vector.
862893

863894
----
864895

0 commit comments

Comments
 (0)