Home » Java » Core Java (page 4)

Core Java

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 »

Candidate JEPs: Records and Sealed Types

Mark Reinhold announced two new closely related candidate JDK Enhancement Proposals (JEPs) on the OpenJDK amber-dev mailing list this week with the posts “New candidate JEP: 359: Records (Preview)” and “New candidate JEP: 360: Sealed Types (Preview).” Both of these candidate JEPs are “preview features” (defined by JEP 12). JEP 359: Records (Preview) The JEP 359 “Summary” states, “Enhance the ...

Read More »

Observer Design Pattern In Java

In this tutorial, we’ll talk about the Observer design pattern. There are two main aspects to the observer pattern – a Subject and the Observers. We use this pattern when our system has multiple objects, known as the observers, relying on the state of one particular object – the subject. All the observers register themselves to the subject. Whenever there ...

Read More »