#Java_Interview_Question
135) What is the difference between ArrayList and Vector?
1️⃣ArrayList is not synchronized.
Vector is synchronized.
2️⃣ArrayList is not a legacy class.
Vector is a legacy class.
3️⃣ArrayList increases its size by 50% of the array size.
Vector increases its size by doubling the array size.
@javaCode☕️
135) What is the difference between ArrayList and Vector?
1️⃣ArrayList is not synchronized.
Vector is synchronized.
2️⃣ArrayList is not a legacy class.
Vector is a legacy class.
3️⃣ArrayList increases its size by 50% of the array size.
Vector increases its size by doubling the array size.
@javaCode☕️
#Composite_Design_Pattern
👉Discussion
Define an abstract base class (Component) that specifies the behavior that needs to be exercised uniformly across all primitive and composite objects. Subclass the Primitive and Composite classes off of the Component class. Each Composite object "couples" itself only to the abstract type Component as it manages its "children".
Use this pattern whenever you have "composites that contain components, each of which could be a composite".
Child management methods [e.g. addChild(), removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Primitives and Composites uniformly requires that these methods be moved to the abstract Component class. See the "Opinions" section below for a discussion of "safety" versus "transparency" issues.
@javaCode☕️
👉Discussion
Define an abstract base class (Component) that specifies the behavior that needs to be exercised uniformly across all primitive and composite objects. Subclass the Primitive and Composite classes off of the Component class. Each Composite object "couples" itself only to the abstract type Component as it manages its "children".
Use this pattern whenever you have "composites that contain components, each of which could be a composite".
Child management methods [e.g. addChild(), removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Primitives and Composites uniformly requires that these methods be moved to the abstract Component class. See the "Opinions" section below for a discussion of "safety" versus "transparency" issues.
@javaCode☕️
👍1
☕️JAVA Language Community
#Composite_Design_Pattern @javaCode☕️
👉Structure
Composites that contain Components, each of which could be a Composite.
Menus that contain menu items, each of which could be a menu.
Row-column GUI layout managers that contain widgets, each of which could be a row-column GUI layout manager.
Directories that contain files, each of which could be a directory.
Containers that contain Elements, each of which could be a Container.
#Composite_Design_Pattern
@javaCode☕️
Composites that contain Components, each of which could be a Composite.
Menus that contain menu items, each of which could be a menu.
Row-column GUI layout managers that contain widgets, each of which could be a row-column GUI layout manager.
Directories that contain files, each of which could be a directory.
Containers that contain Elements, each of which could be a Container.
#Composite_Design_Pattern
@javaCode☕️
👍1
#Java_Interview_Question
136) What is the difference between ArrayList and LinkedList?
1️⃣ArrayList uses a dynamic array. LinkedList uses doubly linked list.
2️⃣ArrayList is not efficient for manipulation because a lot of shifting is required. LinkedList is efficient for manipulation.
3️⃣ArrayList is better to store and fetch data. LinkedList is better to manipulate data.
@javaCode☕️
136) What is the difference between ArrayList and LinkedList?
1️⃣ArrayList uses a dynamic array. LinkedList uses doubly linked list.
2️⃣ArrayList is not efficient for manipulation because a lot of shifting is required. LinkedList is efficient for manipulation.
3️⃣ArrayList is better to store and fetch data. LinkedList is better to manipulate data.
@javaCode☕️
#Composite_Design_Pattern
👉Example
The Composite composes objects into tree structures and lets clients treat individual objects and compositions uniformly. Although the example is abstract, arithmetic expressions are Composites. An arithmetic expression consists of an operand, an operator (+ - * /), and another operand. The operand can be a number, or another arithmetic expression. Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
@javaCode☕️
👉Example
The Composite composes objects into tree structures and lets clients treat individual objects and compositions uniformly. Although the example is abstract, arithmetic expressions are Composites. An arithmetic expression consists of an operand, an operator (+ - * /), and another operand. The operand can be a number, or another arithmetic expression. Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
@javaCode☕️
#Java_Interview_Question
137) What is the difference between Iterator and ListIterator?
Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction.
1) Iterator traverses the elements in forward direction only. ListIterator traverses the elements in backward and forward directions both.
2) Iterator can be used in List, Set and Queue. ListIterator can be used in List only.
@javaCode☕️
137) What is the difference between Iterator and ListIterator?
Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction.
1) Iterator traverses the elements in forward direction only. ListIterator traverses the elements in backward and forward directions both.
2) Iterator can be used in List, Set and Queue. ListIterator can be used in List only.
@javaCode☕️
👍1
#Java_Interview_Question
138) What is the difference between Iterator and Enumeration?
1) Iterator can traverse legacy and non-legacy elements.
Enumeration can traverse only legacy elements.
2) Iterator is fail-fast.
Enumeration is not fail-fast.
3) Iterator is slower than Enumeration.
Enumeration is faster than Iterator.
@javaCode☕️
138) What is the difference between Iterator and Enumeration?
1) Iterator can traverse legacy and non-legacy elements.
Enumeration can traverse only legacy elements.
2) Iterator is fail-fast.
Enumeration is not fail-fast.
3) Iterator is slower than Enumeration.
Enumeration is faster than Iterator.
@javaCode☕️
#Composite_Design_Pattern
👉Check list
1️⃣Ensure that your problem is about representing "whole-part" hierarchical relationships.
2️⃣Consider the heuristic, "Containers that contain containees, each of which could be a container." For example, "Assemblies that contain components, each of which could be an assembly." Divide your domain concepts into container classes, and containee classes.
3️⃣Create a "lowest common denominator" interface that makes your containers and containees interchangeable. It should specify the behavior that needs to be exercised uniformly across all containee and container objects.
4️⃣All container and containee classes declare an "is a" relationship to the interface.
5️⃣All container classes declare a one-to-many "has a" relationship to the interface.
6️⃣Container classes leverage polymorphism to delegate to their containee objects.
7️⃣Child management methods [e.g. addChild(), removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Leaf and Composite objects uniformly may require that these methods be promoted to the abstract Component class. See the Gang of Four for a discussion of these "safety" versus "transparency" trade-offs.
@javaCode☕️
👉Check list
1️⃣Ensure that your problem is about representing "whole-part" hierarchical relationships.
2️⃣Consider the heuristic, "Containers that contain containees, each of which could be a container." For example, "Assemblies that contain components, each of which could be an assembly." Divide your domain concepts into container classes, and containee classes.
3️⃣Create a "lowest common denominator" interface that makes your containers and containees interchangeable. It should specify the behavior that needs to be exercised uniformly across all containee and container objects.
4️⃣All container and containee classes declare an "is a" relationship to the interface.
5️⃣All container classes declare a one-to-many "has a" relationship to the interface.
6️⃣Container classes leverage polymorphism to delegate to their containee objects.
7️⃣Child management methods [e.g. addChild(), removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Leaf and Composite objects uniformly may require that these methods be promoted to the abstract Component class. See the Gang of Four for a discussion of these "safety" versus "transparency" trade-offs.
@javaCode☕️
#Composite_Design_Pattern
👉Rules of thumb
1️⃣Composite and Decorator have similar structure diagrams, reflecting the fact that both rely on recursive composition to organize an open-ended number of objects.
2️⃣Composite can be traversed with Iterator. Visitor can apply an operation over a Composite. Composite could use Chain of Responsibility to let components access global properties through their parent. It could also use Decorator to override these properties on parts of the composition. It could use Observer to tie one object structure to another and State to let a component change its behavior as its state changes.
3️⃣Composite can let you compose a Mediator out of smaller pieces through recursive composition.
4️⃣Decorator is designed to let you add responsibilities to objects without subclassing. Composite's focus is not on embellishment but on representation. These intents are distinct but complementary. Consequently, Composite and Decorator are often used in concert.
5️⃣Flyweight is often combined with Composite to implement shared leaf nodes.
@javaCode☕️
👉Rules of thumb
1️⃣Composite and Decorator have similar structure diagrams, reflecting the fact that both rely on recursive composition to organize an open-ended number of objects.
2️⃣Composite can be traversed with Iterator. Visitor can apply an operation over a Composite. Composite could use Chain of Responsibility to let components access global properties through their parent. It could also use Decorator to override these properties on parts of the composition. It could use Observer to tie one object structure to another and State to let a component change its behavior as its state changes.
3️⃣Composite can let you compose a Mediator out of smaller pieces through recursive composition.
4️⃣Decorator is designed to let you add responsibilities to objects without subclassing. Composite's focus is not on embellishment but on representation. These intents are distinct but complementary. Consequently, Composite and Decorator are often used in concert.
5️⃣Flyweight is often combined with Composite to implement shared leaf nodes.
@javaCode☕️
👍1
#Java_Interview_Question
139) What is the difference between List and Set?
List can contain duplicate elements whereas Set contains only unique elements.
@javaCode☕️
139) What is the difference between List and Set?
List can contain duplicate elements whereas Set contains only unique elements.
@javaCode☕️
👍1
#Java_Interview_Question
140) What is the difference between HashSet and TreeSet?
HashSet maintains no order whereas TreeSet maintains ascending order.
@javaCode☕️
140) What is the difference between HashSet and TreeSet?
HashSet maintains no order whereas TreeSet maintains ascending order.
@javaCode☕️
#Java_Interview_Question
141) What is the difference between Set and Map?
Set contains values only whereas Map contains key and values both.
@javaCode☕️
141) What is the difference between Set and Map?
Set contains values only whereas Map contains key and values both.
@javaCode☕️
👍2