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

👉Java Thread Pool

Java Thread pool represents a group of worker threads that are waiting for the job and reuse many times.

In case of thread pool, a group of fixed size threads are created. A thread from the thread pool is pulled out and assigned a job by the service provider. After completion of the job, thread is contained in the thread pool again.

👉Advantage of Java Thread Pool

Better performance It saves time because there is no need to create new thread.

@javaCode☕️
#Java_Interview_Question

👉ThreadGroup in Java

Java provides a convenient way to group multiple threads in a single object. In such way, we can suspend, resume or interrupt group of threads by a single method call.

@javaCode☕️
#Java_Interview_Question

❗️Note: Now suspend(), resume() and stop() methods are deprecated.

@javaCode☕️
👍1
☕️JAVA Language Community
#Adapter_Design_Pattern @javaCode
#Design_Patterns
#Adapter_Design_Pattern

👉Discussion

Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.

It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.

Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.

Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.

@javaCode☕️
☕️JAVA Language Community
#Design_Patterns #Adapter_Design_Pattern 👉Discussion Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the…
#Adapter_Design_Pattern

👉Structure

Below, a legacy Rectangle component's display() method expects to receive "x, y, w, h" parameters. But the client wants to pass "upper left x and y" and "lower right x and y". This incongruity can be reconciled by adding an additional level of indirection – i.e. an Adapter object.

@javaCode☕️
The Adapter could also be thought of as a "wrapper".

@javaCode
#Java_Interview_Question

👉Java Shutdown Hook

The shutdown hook can be used to perform cleanup resource or save the state when JVM shuts down normally or abruptly. Performing clean resource means closing log file, sending some alerts or something else. So if you want to execute some code before JVM shuts down, use shutdown hook.

@javaCode☕️
☕️JAVA Language Community
#Adapter_Design_Pattern @javaCode
#Adapter_Design_Pattern

👉Example

The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients. Socket wrenches provide an example of the Adapter. A socket attaches to a ratchet, provided that the size of the drive is the same. Typical drive sizes in the United States are 1/2" and 1/4". Obviously, a 1/2" drive ratchet will not fit into a 1/4" drive socket unless an adapter is used. A 1/2" to 1/4" adapter has a 1/2" female connection to fit on the 1/2" drive ratchet, and a 1/4" male connection to fit in the 1/4" drive socket.

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