Singleton Pattern
Singleton Pattern
4h 56m

This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.

Learning Objectives

  • Understand what design patterns are
  • Learn about the myriad of design patterns that you can use in your projects

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.


Basic knowledge of Java programming.



Hello, dear friends. In this video, we will examine Singleton Design Pattern. Let's begin. Singleton design pattern is in the category of creational design pattern. The purpose of this design pattern is to create only one instance of a class. In other words, when an instance is wanted to be created from any class, if there is no instance created before, a new one is created. If it has been created before, the existing instance is used. You can see the UML diagram of the singleton design pattern. According to this schema, to create the singleton class, we need to have static member of class, private constructor, and static factory method. If you want, let's create a project with singleton. First, create a new project and name it Singleton. We will implement singleton into a database connection project.

Add new class and name it Database. As I said, first we need a private constructor. Now it's time to create a static method called getInstance( ). If we already have an instance, we don't need to create a new one. So, we have to check if it is null or not. It is null, create an instance. Return. Let's add a create connection method. System.out. Let's send a message. Let's call this in main. Database, database. Call database getInstance( ) ; Now, get connection. Done. If we run the project, we can see the connection is successful message. Run. Look, I hope your understanding of singleton is a little better now. In the next video, we will look into the abstract factory pattern. See you in the next video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics