#Adapter_Design_Pattern
👉Check list
1️⃣Identify the players: the component(s) that want to be accommodated (i.e. the client), and the component that needs to adapt (i.e. the adaptee).
2️⃣Identify the interface that the client requires.
3️⃣Design a "wrapper" class that can "impedance match" the adaptee to the client.
4️⃣The adapter/wrapper class "has a" instance of the adaptee class.
5️⃣The adapter/wrapper class "maps" the client interface to the adaptee interface.
6️⃣The client uses (is coupled to) the new interface
@javaCode☕️
👉Check list
1️⃣Identify the players: the component(s) that want to be accommodated (i.e. the client), and the component that needs to adapt (i.e. the adaptee).
2️⃣Identify the interface that the client requires.
3️⃣Design a "wrapper" class that can "impedance match" the adaptee to the client.
4️⃣The adapter/wrapper class "has a" instance of the adaptee class.
5️⃣The adapter/wrapper class "maps" the client interface to the adaptee interface.
6️⃣The client uses (is coupled to) the new interface
@javaCode☕️
#Java_Interview_Question
106)How to perform single task by multiple threads?
If you have to perform single task by many threads, have only one run() method.
@javaCode☕️
106)How to perform single task by multiple threads?
If you have to perform single task by many threads, have only one run() method.
@javaCode☕️
#Adapter_Design_Pattern
👉Rules of thumb
1️⃣Adapter makes things work after they're designed; Bridge makes them work before they are.
2️⃣Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together.
3️⃣Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface.
4️⃣Adapter is meant to change the interface of an existing object. Decorator enhances another object without changing its interface. Decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn't possible with pure Adapters.
5️⃣Facade defines a new interface, whereas Adapter reuses an old interface. Remember that Adapter makes two existing interfaces work together as opposed to defining an entirely new one.
@javaCode☕️
👉Rules of thumb
1️⃣Adapter makes things work after they're designed; Bridge makes them work before they are.
2️⃣Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together.
3️⃣Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface.
4️⃣Adapter is meant to change the interface of an existing object. Decorator enhances another object without changing its interface. Decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn't possible with pure Adapters.
5️⃣Facade defines a new interface, whereas Adapter reuses an old interface. Remember that Adapter makes two existing interfaces work together as opposed to defining an entirely new one.
@javaCode☕️
#Java_Interview_Question
107) What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main advantage is:
Threads share the same address space.
Thread is lightweight.
Cost of communication between process is low.
@javaCode☕️
107) What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main advantage is:
Threads share the same address space.
Thread is lightweight.
Cost of communication between process is low.
@javaCode☕️
#Java_Interview_Question
108) What does join() method?
The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task.
@javaCode☕️
108) What does join() method?
The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task.
@javaCode☕️
#Java_Interview_Question
109) What is difference between wait() and sleep() method?
1) The wait() method is defined in Object class.
The sleep() method is defined in Thread class.
2) wait() method releases the lock.
The sleep() method doesn't releases the lock.
@javaCode☕️
109) What is difference between wait() and sleep() method?
1) The wait() method is defined in Object class.
The sleep() method is defined in Thread class.
2) wait() method releases the lock.
The sleep() method doesn't releases the lock.
@javaCode☕️
#Java_Interview_Question
110)When should we interrupt a thread?
We should interrupt a thread if we want to break out the sleep or wait state of a thread.
@javaCode☕️
110)When should we interrupt a thread?
We should interrupt a thread if we want to break out the sleep or wait state of a thread.
@javaCode☕️
#Java_Interview_Question
111) What is synchronization?
Synchronization is the capabilility of control the access of multiple threads to any shared resource.It is used:
1️⃣To prevent thread interference.
2️⃣To prevent consistency problem.
@javaCode☕️
111) What is synchronization?
Synchronization is the capabilility of control the access of multiple threads to any shared resource.It is used:
1️⃣To prevent thread interference.
2️⃣To prevent consistency problem.
@javaCode☕️
#Java_Interview_Question
112) What is the purpose of Synchronized block?
1️⃣Synchronized block is used to lock an object for any shared resource.
2️⃣Scope of synchronized block is smaller than the method.
@javaCode☕️
112) What is the purpose of Synchronized block?
1️⃣Synchronized block is used to lock an object for any shared resource.
2️⃣Scope of synchronized block is smaller than the method.
@javaCode☕️
#Java_Interview_Question
113)Can Java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.
@javaCode☕️
113)Can Java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.
@javaCode☕️
#Java_Interview_Question
114) What is static synchronization?
If you make any static method as synchronized, the lock will be on the class not on object.
@javaCode☕️
114) What is static synchronization?
If you make any static method as synchronized, the lock will be on the class not on object.
@javaCode☕️
#Design_Patterns
#Bridge_Design_Pattern
👉Intent
▪️Decouple an abstraction from its implementation so that the two can vary independently.
▪️Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
▪️Beyond encapsulation, to insulation
@javaCode☕️
#Bridge_Design_Pattern
👉Intent
▪️Decouple an abstraction from its implementation so that the two can vary independently.
▪️Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
▪️Beyond encapsulation, to insulation
@javaCode☕️
#Bridge_Design_Pattern
👉Problem
"Hardening of the software arteries" has occurred by using subclassing of an abstract base class to provide alternative implementations. This locks in compile-time binding between interface and implementation. The abstraction and implementation cannot be independently extended or composed.
@javaCode☕️
👉Problem
"Hardening of the software arteries" has occurred by using subclassing of an abstract base class to provide alternative implementations. This locks in compile-time binding between interface and implementation. The abstraction and implementation cannot be independently extended or composed.
@javaCode☕️
#Java_Interview_Question
115)What is the difference between notify() and notifyAll()?
The notify() is used to unblock one waiting thread whereas notifyAll() method is used to unblock all the threads in waiting state.
@javaCode☕️
115)What is the difference between notify() and notifyAll()?
The notify() is used to unblock one waiting thread whereas notifyAll() method is used to unblock all the threads in waiting state.
@javaCode☕️
#Java_Interview_Question
116)What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.
@javaCode☕️
116)What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.
@javaCode☕️
☕️JAVA Language Community
#Bridge_Design_Pattern
👉Motivation
Consider the domain of "thread scheduling".
There are two types of thread schedulers, and two types of operating systems or "platforms". Given this approach to specialization, we have to define a class for each permutation of these two dimensions. If we add a new platform (say ... Java's Virtual Machine), what would our hierarchy look like?
@javaCode☕️
Consider the domain of "thread scheduling".
There are two types of thread schedulers, and two types of operating systems or "platforms". Given this approach to specialization, we have to define a class for each permutation of these two dimensions. If we add a new platform (say ... Java's Virtual Machine), what would our hierarchy look like?
@javaCode☕️