#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☕️
☕️JAVA Language Community
#Bridge_Design_Pattern
What if we had three kinds of thread schedulers, and four kinds of platforms? What if we had five kinds of thread schedulers, and ten kinds of platforms? The number of classes we would have to define is the product of the number of scheduling schemes and the number of platforms.
@javaCode☕️
@javaCode☕️
☕️JAVA Language Community
#Bridge_Design_Pattern
The Bridge design pattern proposes refactoring this exponentially explosive inheritance hierarchy into two orthogonal hierarchies – one for platform-independent abstractions, and the other for platform-dependent implementations.
@javaCode☕️
@javaCode☕️
#Java_Interview_Question
117) What is Garbage Collection?
Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management.
@javaCode☕️
117) What is Garbage Collection?
Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management.
@javaCode☕️
☕️JAVA Language Community
#Java_Interview_Question 117) What is Garbage Collection? Garbage collection is a process of reclaiming the runtime unused objects.It is performed for memory management. @javaCode☕️
#Java_Interview_Question
👉Java Garbage Collection
▪️In java, garbage means unreferenced objects.
▪️Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.
▪️To do so, we were using free() function in C language and delete() in C++. But, in java it is performed automatically. So, java provides better memory management.
👉Advantage of Garbage Collection
1️⃣It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.
2️⃣It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.
@javaCode☕️
👉Java Garbage Collection
▪️In java, garbage means unreferenced objects.
▪️Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.
▪️To do so, we were using free() function in C language and delete() in C++. But, in java it is performed automatically. So, java provides better memory management.
👉Advantage of Garbage Collection
1️⃣It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.
2️⃣It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.
@javaCode☕️
#Bridge_Design_Pattern
👉Discussion
Decompose the component's interface and implementation into orthogonal class hierarchies. The interface class contains a pointer to the abstract implementation class. This pointer is initialized with an instance of a concrete implementation class, but all subsequent interaction from the interface class to the implementation class is limited to the abstraction maintained in the implementation base class. The client interacts with the interface class, and it in turn "delegates" all requests to the implementation class.
The interface object is the "handle" known and used by the client; while the implementation object, or "body", is safely encapsulated to ensure that it may continue to evolve, or be entirely replaced (or shared at run-time.
👉Use the Bridge pattern when:
1️⃣you want run-time binding of the implementation,
2️⃣you have a proliferation of classes resulting from a coupled interface and numerous implementations,
3️⃣you want to share an implementation among multiple objects,
4️⃣you need to map orthogonal class hierarchies.
👉Consequences include:
1️⃣decoupling the object's interface,
2️⃣improved extensibility (you can extend (i.e. subclass) the abstraction and implementation hierarchies independently),
3️⃣hiding details from clients.
👉Bridge is a synonym for the "handle/body" idiom. This is a design mechanism that encapsulates an implementation class inside of an interface class. The former is the body, and the latter is the handle. The handle is viewed by the user as the actual class, but the work is done in the body. "The handle/body class idiom may be used to decompose a complex abstraction into smaller, more manageable classes. The idiom may reflect the sharing of a single resource by multiple classes that control access to it (e.g. reference counting)."
@javaCode☕️
👉Discussion
Decompose the component's interface and implementation into orthogonal class hierarchies. The interface class contains a pointer to the abstract implementation class. This pointer is initialized with an instance of a concrete implementation class, but all subsequent interaction from the interface class to the implementation class is limited to the abstraction maintained in the implementation base class. The client interacts with the interface class, and it in turn "delegates" all requests to the implementation class.
The interface object is the "handle" known and used by the client; while the implementation object, or "body", is safely encapsulated to ensure that it may continue to evolve, or be entirely replaced (or shared at run-time.
👉Use the Bridge pattern when:
1️⃣you want run-time binding of the implementation,
2️⃣you have a proliferation of classes resulting from a coupled interface and numerous implementations,
3️⃣you want to share an implementation among multiple objects,
4️⃣you need to map orthogonal class hierarchies.
👉Consequences include:
1️⃣decoupling the object's interface,
2️⃣improved extensibility (you can extend (i.e. subclass) the abstraction and implementation hierarchies independently),
3️⃣hiding details from clients.
👉Bridge is a synonym for the "handle/body" idiom. This is a design mechanism that encapsulates an implementation class inside of an interface class. The former is the body, and the latter is the handle. The handle is viewed by the user as the actual class, but the work is done in the body. "The handle/body class idiom may be used to decompose a complex abstraction into smaller, more manageable classes. The idiom may reflect the sharing of a single resource by multiple classes that control access to it (e.g. reference counting)."
@javaCode☕️