Wednesday, 22 February 2017

Implementing the Singleton Design Pattern in Java

The Singleton design pattern is one of the most popular design patterns in use. The Singleton design pattern is one of the Gang of Four's (GOF) design patterns and belongs to the Creational Design Pattern category. This article presents a discussion on the Singleton design pattern, its benefits and how it can be implemented in Java.

What is the Singleton Design Pattern?

The Singleton design pattern is used to restrict instances of a class to just one instance. This design pattern states that there can be one — and only one — instance of a class throughout the application's lifecycle. Essentially, a singleton class is one that can have just one instance throughout the application's life cycle and provides a global point of access to it.

Tuesday, 21 February 2017

Working with Files and I/O in Java

The java.nio package contains the types required to perform input output operations in Java. The introduction of the java.nio package has simplified input — output operations. This article presents a discussion on how to perform input — output operations in Java with special focus on the java.nio package.

When you work with files for I/O, you basically work with streams. A stream may be defined as a sequence of bytes. There are two types of streams. These include: input stream and output stream. While the former is used to read data from a source, the latter is used to write data to a destination.