☕️JAVA Language Community
2.91K subscribers
144 photos
7 videos
31 files
42 links
☕️ Software, IT, Java, news
💻 IT highlights
🎯 AI update
🖥⌨️🖱
Download Telegram
#Java_Interview_Question

104)When does the JVM shut down?

The JVM shuts down when:
user presses ctrl+c on the command prompt
System.exit(int) method is invoked
user logoff
user shutdown etc.

@javaCode☕️
#Java_Interview_Question

105) What is Factory method?

The method that returns the instance of a class is known as factory method.

@javaCode☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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☕️
#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

👉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☕️