Singleton design pattern is a Creational design pattern.It means create a single object or instance and make it global ,In other words, a class must ensure that only single object should be created and single object can be used by all other classes. There are two forms of singleton design pattern Early Instantiation: creation of instance at load time. (private static A obj= new A();) Lazy Instantiation: creation of instance when required. (private static A obj; ) Advantage of Singleton design pattern Saves memory because object is not created at each request. Only single instance is reused again and again. To create the singleton class, we need to have static member of class, private constructor and static factory method. Static member: It gets memory only once because of static, itcontains the instance of the Singleton class. Private constructor: It will prevent to instantiate the Singleton class from outside the class. ...
import java.util.Scanner; public class SocondLargest { public static void main(String[] args) { int secondlargest = Integer.MIN_VALUE; int largest = Integer.MIN_VALUE; System.out.println(largest); Scanner input = new Scanner(System.in); System.out.println("Enter array values: "); int arr[] = new int[5]; for (int i = 0; i < arr.length; i++) { arr[i] = input.nextInt(); if (largest < arr[i]) { secondlargest = largest; largest = arr[i]; ...