☕️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☕️
☕️JAVA Language Community
#Bridge_Design_Pattern
👉Structure
The Client doesn't want to deal with platform-dependent details. The Bridge pattern encapsulates this complexity behind an abstraction "wrapper".
Bridge emphasizes identifying and decoupling "interface" abstraction from "implementation" abstraction.
@javaCode☕️
The Client doesn't want to deal with platform-dependent details. The Bridge pattern encapsulates this complexity behind an abstraction "wrapper".
Bridge emphasizes identifying and decoupling "interface" abstraction from "implementation" abstraction.
@javaCode☕️
#Java_Interview_Question
118) What is gc()?
gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection.
@javaCode☕️
118) What is gc()?
gc() is a daemon thread.gc() method is defined in System class that is used to send request to JVM to perform garbage collection.
@javaCode☕️
#Java_Interview_Question
119) What is the purpose of finalize() method?
finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup processing.
@javaCode☕️
119) What is the purpose of finalize() method?
finalize() method is invoked just before the object is garbage collected.It is used to perform cleanup processing.
@javaCode☕️
#Java_Interview_Question
121)What kind of thread is the Garbage collector thread?
Daemon thread.
@javaCode☕️
121)What kind of thread is the Garbage collector thread?
Daemon thread.
@javaCode☕️
☕️JAVA Language Community
#Bridge_Design_Pattern
👉Example
The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently. A household switch controlling lights, ceiling fans, etc. is an example of the Bridge. The purpose of the switch is to turn a device on or off. The actual switch can be implemented as a pull chain, simple two position switch, or a variety of dimmer switches.
@javaCode☕️
The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently. A household switch controlling lights, ceiling fans, etc. is an example of the Bridge. The purpose of the switch is to turn a device on or off. The actual switch can be implemented as a pull chain, simple two position switch, or a variety of dimmer switches.
@javaCode☕️
#Java_Interview_Question
122)What is difference between final, finally and finalize?
final: final is a keyword, final can be variable, method or class.You, can't change the value of final variable, can't override final method, can't inherit final class.
finally: finally block is used in exception handling. finally block is always executed.
finalize():finalize() method is used in garbage collection.finalize() method is invoked just before the object is garbage collected.The finalize() method can be used to perform any cleanup processing.
@javaCode☕️
122)What is difference between final, finally and finalize?
final: final is a keyword, final can be variable, method or class.You, can't change the value of final variable, can't override final method, can't inherit final class.
finally: finally block is used in exception handling. finally block is always executed.
finalize():finalize() method is used in garbage collection.finalize() method is invoked just before the object is garbage collected.The finalize() method can be used to perform any cleanup processing.
@javaCode☕️
#Java_Interview_Question
123)What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
@javaCode☕️
123)What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
@javaCode☕️
#Java_Interview_Question
124)How will you invoke any external process in Java?
By Runtime.getRuntime().exec(?) method.
@javaCode☕️
124)How will you invoke any external process in Java?
By Runtime.getRuntime().exec(?) method.
@javaCode☕️
#Bridge_Design_Pattern
👉Check list
1️⃣Decide if two orthogonal dimensions exist in the domain. These independent concepts could be: abstraction/platform, or domain/infrastructure, or front-end/back-end, or interface/implementation.
2️⃣Design the separation of concerns: what does the client want, and what do the platforms provide.
3️⃣Design a platform-oriented interface that is minimal, necessary, and sufficient. Its goal is to decouple the abstraction from the platform.
4️⃣Define a derived class of that interface for each platform.
5️⃣Create the abstraction base class that "has a" platform object and delegates the platform-oriented functionality to it.
6️⃣Define specializations of the abstraction class if desired.
@javaCode☕️
👉Check list
1️⃣Decide if two orthogonal dimensions exist in the domain. These independent concepts could be: abstraction/platform, or domain/infrastructure, or front-end/back-end, or interface/implementation.
2️⃣Design the separation of concerns: what does the client want, and what do the platforms provide.
3️⃣Design a platform-oriented interface that is minimal, necessary, and sufficient. Its goal is to decouple the abstraction from the platform.
4️⃣Define a derived class of that interface for each platform.
5️⃣Create the abstraction base class that "has a" platform object and delegates the platform-oriented functionality to it.
6️⃣Define specializations of the abstraction class if desired.
@javaCode☕️
#Java_Interview_Question
125)What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
@javaCode☕️
125)What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
@javaCode☕️
#Java_Interview_Question
126)What an I/O filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
@javaCode☕️
126)What an I/O filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
@javaCode☕️
#Bridge_Design_Pattern
👉Rules of thumb
▪️Adapter makes things work after they're designed; Bridge makes them work before they are.
▪️Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together.
▪️State, Strategy, Bridge (and to some degree Adapter) have similar solution structures. They all share elements of the "handle/body" idiom. They differ in intent - that is, they solve different problems.
▪️The structure of State and Bridge are identical (except that Bridge admits hierarchies of envelope classes, whereas State allows only one). The two patterns use the same structure to solve different problems: State allows an object's behavior to change along with its state, while Bridge's intent is to decouple an abstraction from its implementation so that the two can vary independently.
▪️If interface classes delegate the creation of their implementation classes (instead of creating/coupling themselves directly), then the design usually uses the Abstract Factory pattern to create the implementation objects.
@javaCode☕️
👉Rules of thumb
▪️Adapter makes things work after they're designed; Bridge makes them work before they are.
▪️Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together.
▪️State, Strategy, Bridge (and to some degree Adapter) have similar solution structures. They all share elements of the "handle/body" idiom. They differ in intent - that is, they solve different problems.
▪️The structure of State and Bridge are identical (except that Bridge admits hierarchies of envelope classes, whereas State allows only one). The two patterns use the same structure to solve different problems: State allows an object's behavior to change along with its state, while Bridge's intent is to decouple an abstraction from its implementation so that the two can vary independently.
▪️If interface classes delegate the creation of their implementation classes (instead of creating/coupling themselves directly), then the design usually uses the Abstract Factory pattern to create the implementation objects.
@javaCode☕️
#Java_Interview_Question
127) What is serialization?
Serialization is a process of writing the state of an object into a byte stream.It is mainly used to travel object's state on the network.
@javaCode☕️
127) What is serialization?
Serialization is a process of writing the state of an object into a byte stream.It is mainly used to travel object's state on the network.
@javaCode☕️
☕️JAVA Language Community
Photo
#Java_Interview_Question
👉Serialization in Java
Serialization in java is a mechanism of writing the state of an object into a byte stream.
It is mainly used in Hibernate, RMI, JPA, EJB and JMS technologies.
The reverse operation of serialization is called deserialization.
👉Advantage of Java Serialization
It is mainly used to travel object's state on the network (known as marshaling).
@javaCode☕️
👉Serialization in Java
Serialization in java is a mechanism of writing the state of an object into a byte stream.
It is mainly used in Hibernate, RMI, JPA, EJB and JMS technologies.
The reverse operation of serialization is called deserialization.
👉Advantage of Java Serialization
It is mainly used to travel object's state on the network (known as marshaling).
@javaCode☕️