Home » Java » Core Java (page 5)

Core Java

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 »

Template Method Pattern In Java

The template method pattern is a behavioral pattern which suggests defining an algorithm more generally in the superclass. The algorithm is defined within a method known as the template method. The subclasses only define the implementation of the more specific algorithmic steps. The benefit of using this design pattern is that any changes later in the algorithm will only impact ...

Read More »

Decorator Design Pattern In Java

A decorator design pattern allows dynamically attaching the additional responsibilities or behaviors to an object at runtime. It is a structural pattern and makes use of aggregation to combine those behaviors. In this tutorial, we’ll learn to implement the decorator pattern. UML Diagram: Let’s start by looking at the UML representation of a decorator pattern: The ConcreteComponent class is the ...

Read More »

Proxy Design Pattern In Java

Proxy objects or the surrogates provide a placeholder for another object to control access to that object. A proxy acts as a lightweight or the simplified version of the original object. It supports the same operations as the original object but may delegate those requests to the original object to achieve them. The Proxy design pattern is a structural pattern ...

Read More »