1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Using Design Patterns in Java Projects

Singleton Pattern

Contents

keyboard_tab
Design Patterns
1
Design Patterns
PREVIEW2m 26s
2
Singleton Pattern
PREVIEW3m 13s
9
Decorator
7m 48s
10
Flyweight
9m 20s
11
Proxy
7m 36s
12
Facade
6m 5s
14
Command
11m 44s
15
Iterator
8m 24s
16
Visitor
9m 4s
17
Mediator
11m 38s
18
Memento
9m 48s
19
Observer
10m 40s
20
Strategy
8m 27s
21
State
10m 27s
22
Template
7m 56s
23
MVC
10m 27s
26
DAO
10m 27s
27

The course is part of this learning path

Singleton Pattern
Overview
Difficulty
Intermediate
Duration
4h 56m
Students
22
Ratings
5/5
starstarstarstarstar
Description

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.

Prerequisites

Basic knowledge of Java programming.

 

Transcript

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
Students
433
Courses
47
Learning Paths
2

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