☕️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 Language Community
👉Rules of thumb 1️⃣Sometimes creational patterns are competitors: there are cases when either Prototype or Abstract Factory could be used profitably. At other times they are complementary: Abstract Factory might store a set of Prototypes from which to clone…
3️⃣Abstract Factory classes are often implemented with Factory Methods, but they can also be implemented using Prototype.

4️⃣Abstract Factory can be used as an alternative to Facade to hide platform-specific classes.

5️⃣Builder focuses on constructing a complex object step by step.Abstract Factory emphasizes a family of product objects (either simple or complex). Builder returns the product as a final step, but as far as the Abstract Factory is concerned, the product gets returned immediately.

@javaCode☕️
☕️JAVA Language Community
3️⃣Abstract Factory classes are often implemented with Factory Methods, but they can also be implemented using Prototype. 4️⃣Abstract Factory can be used as an alternative to Facade to hide platform-specific classes. 5️⃣Builder focuses on constructing a…
6️⃣Builder is to creation as Strategy is to algorithm.

7️⃣Builder often builds a Composite.

8️⃣Factory Methods are usually called within Template methods.

9️⃣Factory Method: creation through inheritance. Prototype: creation through delegation.

🔟Often, designs start out using Factory Method (less complicated, more customizable, subclasses proliferate) and evolve toward Abstract Factory, Prototype, or Builder (more flexible, more complex) as the designer discovers where more flexibility is needed.

1️⃣1️⃣Prototype doesn't require subclassing, but it does require an Initialize operation. Factory Method requires subclassing, but doesn't require Initialize.

1️⃣2️⃣Designs that make heavy use of the Composite and Decorator patterns often can benefit from Prototype as well.

@javaCode☕️
#Java_Interview_Question

101) Can we start a thread twice

No. After starting a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown. In such case, thread will run once but for second time, it will throw exception.

@javaCode☕️
#Java_Interview_Question

102) What if we call run() method directly instead start() method?

Each thread starts in a separate call stack.
Invoking the run() method from main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack.

@javaCode☕️
#Design_Patterns

#Structural_patterns

▪️In Software Engineering, Structural Design Patterns are Design Patterns that ease the design by identifying a simple way to realize relationships between entities.


1️⃣ #Adapter_Design_Pattern
Match interfaces of different classes

2️⃣ #Bridge_Design_Pattern
Separates an object's interface from its implementation

3️⃣ #Composite_Design_Pattern
A tree structure of simple and composite objects

4️⃣ #Decorator_Design_Pattern
Add responsibilities to objects dynamically

5️⃣ #Facade_Design_Pattern
A single class that represents an entire subsystem

6️⃣ #Flyweight_Design_Pattern
A fine-grained instance used for efficient sharing

7️⃣ #PrivateClassData_Design_Pattern
Restricts accessor/mutator access

8️⃣ #Proxy_Design_Pattern
An object representing another object

@javaCode☕️
#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☕️
#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☕️
❗️Note: If you want to make a user thread as Daemon, it must not be started otherwise it will throw IllegalThreadStateException.

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