Home » Java » Core Java » Page 9

Core Java

SOLID Design Principles

Introduction: Robert C. Martin defined five object-oriented design principles: Single-Responsibility PrincipleOpen-Closed PrincipleLiskov’s Substitution PrincipleInterface Segregation Principle, andDependency Inversion Principle These together are popularly known as the SOLID principles. When designing an object-oriented system, we should try to stick to these principles wherever possible. These principles help us design a system that’s more extensible, understandable and maintainable. Using these principles can ...

Read More »

Strategy Design Pattern In Java

The strategy design pattern is a behavioral pattern in which we have multiple algorithms/strategies for achieving a task and which algorithm/strategy to use is left for the client to choose. The various algorithm options are encapsulated in individual classes. In this tutorial, we’ll learn to implement the strategy design pattern in Java. UML Representation: Let’s first start by looking at ...

Read More »

Mediator Design Pattern In Java

In this tutorial, we’ll learn about a behavioral pattern that promotes loose coupling between several objects communicating with one another. The idea behind the Mediator design pattern is to have a central object that encapsulates how a set of objects interact. In the mediator pattern, we extract all the relationships between different classes in a separate class known as a ...

Read More »

Chain Of Responsibility Design Pattern In Java

In this tutorial, we’ll learn how to implement the Chain Of Responsibility Pattern in Java. The Chain Of Responsibility design pattern involves having a chain of objects that are together responsible for handling a request. When a client sends a request, the first handler will try to process it. If it can process it, then the request processing ends here. ...

Read More »

Command Design Pattern In Java

In this tutorial, we’ll learn about the command pattern which is an important behavioral design pattern. It has some important applications like implementing undo/redo functionality in text editors. In the command design pattern, there’s a command object that sits between the sender and the receiver objects. The sender object can create a command object. The command object then calls the ...

Read More »

Tools to keep JavaDoc up-to-date

There are many projects where the documentation is not up-to-date. It is easy to forget to change the documentation after the code was changed. The reason is fairly understandable. There is a change in the code, then debug, then hopefully change in the tests (or the other way around in the reverse order if you are more TDD) and then ...

Read More »

State Design Pattern In Java

In this tutorial, we’ll explore another popular behavioral design pattern – the State Design Pattern. The knowledge of state design pattern comes handy when we’re working with an object which can exist in multiple states. We should use it primarily when the behavior of an object depends on its current state. This pattern helps us avoid long conditional checks of ...

Read More »

Java Serialization Magic Methods And Their Uses With Example

In a previous article Everything You Need to Know About Java Serialization, we discussed how serializability of a class is enabled by implementing theSerializable interface. If our class does not implement Serializable interface or if it is having a reference to a non Serializable class then JVM will throw NotSerializableException. All subtypes of a serializable class are themselves serializable andExternalizable ...

Read More »

Java Performance: For-eaching vs. Streaming

Is counting upwards or downwards in a for-loop the most efficient way of iterating? Sometimes the answer is neither. Read this post and understand the impact of different iteration varieties. Iteration Performance There are many views on how to iterate with high performance. The traditional way of iterating in Java has been a for-loop starting at zero and then counting ...

Read More »