#Java_Interview_Question
👉Daemon Thread in Java
Daemon thread in java is a service provider thread that provides services to the user thread. Its life depend on the mercy of user threads i.e. when all the user threads dies, JVM terminates this thread automatically.
There are many java daemon threads running automatically e.g. gc, finalizer etc.
You can see all the detail by typing the jconsole in the command prompt. The jconsole tool provides information about the loaded classes, memory usage, running threads etc.
👉Points to remember for Daemon Thread in Java
▪️It provides services to user threads for background supporting tasks. It has no role in life than to serve user threads.
▪️Its life depends on user threads.
▪️It is a low priority thread.
@javaCode☕️
👉Daemon Thread in Java
Daemon thread in java is a service provider thread that provides services to the user thread. Its life depend on the mercy of user threads i.e. when all the user threads dies, JVM terminates this thread automatically.
There are many java daemon threads running automatically e.g. gc, finalizer etc.
You can see all the detail by typing the jconsole in the command prompt. The jconsole tool provides information about the loaded classes, memory usage, running threads etc.
👉Points to remember for Daemon Thread in Java
▪️It provides services to user threads for background supporting tasks. It has no role in life than to serve user threads.
▪️Its life depends on user threads.
▪️It is a low priority thread.
@javaCode☕️
#Java_Interview_Question
103) Why JVM terminates the daemon thread if there is no user thread?
The sole purpose of the daemon thread is that it provides services to user thread for background supporting task. If there is no user thread, why should JVM keep running this thread. That is why JVM terminates the daemon thread if there is no user thread.
@javaCode☕️
103) Why JVM terminates the daemon thread if there is no user thread?
The sole purpose of the daemon thread is that it provides services to user thread for background supporting task. If there is no user thread, why should JVM keep running this thread. That is why JVM terminates the daemon thread if there is no user thread.
@javaCode☕️
❗️Note: If you want to make a user thread as Daemon, it must not be started otherwise it will throw IllegalThreadStateException.
@javaCode☕️
@javaCode☕️
#Design_Patterns
#Adapter_Design_Pattern
👉Intent
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
▪️Wrap an existing class with a new interface.
▪️Impedance match an old component to a new system
@javaCode☕️
#Adapter_Design_Pattern
👉Intent
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
▪️Wrap an existing class with a new interface.
▪️Impedance match an old component to a new system
@javaCode☕️
☕️JAVA Language Community
#Design_Patterns #Adapter_Design_Pattern 👉Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. ▪️Wrap an existing class with a new…
#Adapter_Design_Pattern
👉Problem
An "off the shelf" component offers compelling functionality that you would like to reuse, but its "view of the world" is not compatible with the philosophy and architecture of the system currently being developed.
@javaCode☕️
👉Problem
An "off the shelf" component offers compelling functionality that you would like to reuse, but its "view of the world" is not compatible with the philosophy and architecture of the system currently being developed.
@javaCode☕️
#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 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☕️
👉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☕️
❗️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☕️
#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☕️
👉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☕️
#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 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☕️
👉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☕️
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☕️
105) What is Factory method?
The method that returns the instance of a class is known as factory method.
@javaCode☕️