Home » Java » Core Java (page 2)

Core Java

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 »

Factory Method Design Pattern

Factory Method pattern is one of the popular creational design patterns. It doesn’t specifically rely on a factory object to create the objects. Rather, the idea is to use a separate method in the same class to create an object. Factory Method pattern defines an interface for creating objects but lets the subclasses decide how to instantiate its objects. Each ...

Read More »

Facade Design Pattern In Java

Facade means the face of a building. While passing across a street, all we look at is the face of a building. The face abstracts all the complex implementation details of a building. Similarly, a facade design pattern aims to provide a unified interface to a set of interfaces in the subsystem. This unified interface hides the subsystem complexity from ...

Read More »