What does early initialization of Singleton class in Java mean


Ancourt

I'm not too sure about the term Singleton class early initialization. Understanding the lifecycle of the Singleton class will also help.

Anubava

Well, Lazy initializationmeans you don't initialize the object before it's first used.

Early initializationJust the opposite, you need to pre-initialize a singleton when loading the class.

There are many ways to do early initialization, one way is to declare a singleton as static.

Here is an example:

public class SingletonClassEarly {
    private static SingletonClassEarly sce = new SingletonClassEarly();
    private SingletonClassEarly() {} // make it private

    public static SingletonClassEarly getInstance() {
        return sce;
    }
}

According to the lifecycle, this singleton will be loaded after the JVM starts and when the class is initialized. On shutdown/exit it is unloaded by the JVM.

Related


What does early initialization of Singleton class in Java mean

Ancourt I'm not too sure about the term Singleton class early initialization. Understanding the lifecycle of the Singleton class will also help. Anubava Well, Lazy initializationmeans you don't initialize the object before it's first used. Early initialization

Java Early Access - What does FCS mean?

oliholz : The last Java 7 I downloaded was named jdk-7-ea-bin-b145-windows-i586-07_jun_2011 now its name jre-7-fcs-bin-b146-windows-i586-20_jun_2011 Replaced ea (early access) with fcs, but what does that fcsmean? Buhak Cindy: First customer shipment. See So

Java Early Access - What does FCS mean?

oliholz : The last Java 7 I downloaded was named jdk-7-ea-bin-b145-windows-i586-07_jun_2011 now its name jre-7-fcs-bin-b146-windows-i586-20_jun_2011 Replaced ea (early access) with fcs, but what does that fcsmean? Buhak Cindy: First customer shipment. See So

Java Early Access - What does FCS mean?

oliholz : The last Java 7 I downloaded was named jdk-7-ea-bin-b145-windows-i586-07_jun_2011 now its name jre-7-fcs-bin-b146-windows-i586-20_jun_2011 Replaced ea (early access) with fcs, but what does that fcsmean? Buhak Cindy: First customer shipment. See So

Class <? > what does it mean in Java?

david99world: My problem is as above. Sorry for the possible duplicate, but couldn't find an example at the end <?>. Why not just use it Classas a parameter? manual: Classis a parameterizable class, so you can use the Class<T>where - Ttype syntax . By writing

What does .class mean in Java?

Quinn Wei: .classWhat does it mean in Java ? For example, if I create a class called Print. What Print.classin return? Javier: When you write .classafter a class name , it refers to a class literal - an object that represents information about a given class .j

What does "Class<?" mean in Java?

Poplar 100 I came across this function definition: public Collection<Class<? extends SomeClass>> someFunc(); What does this Class<?part mean? Coming from C++, it looks like a template, but I'm not sure if that's the case because there are some structs in Java

Class <? > what does it mean in Java?

david99world: My problem is as above. Sorry for the possible duplicate, but couldn't find an example at the end <?>. Why not just use it Classas a parameter? manual: Classis a parameterizable class, so you can use the Class<T>where - Ttype syntax . By writing

What does .class mean in Java?

Quinn Wei: .classWhat does it mean in Java ? For example, if I create a class called Print. What Print.classin return? Javier: When you write .classafter a class name , it refers to a class literal - an object that represents information about a given class .j

What does "Class<?" mean in Java?

Poplar 100 I came across this function definition: public Collection<Class<? extends SomeClass>> someFunc(); What does this Class<?part mean? Coming from C++, it looks like a template, but I'm not sure if that's the case because there are some structs in Java

Class <? > what does it mean in Java?

david99world: My problem is as above. Sorry for the possible duplicate, but couldn't find an example at the end <?>. Why not just use it Classas a parameter? manual: Classis a parameterizable class, so you can use the Class<T>where - Ttype syntax . By writing

What does .class mean in Java?

Quinn Wei: .classWhat does it mean in Java ? For example, if I create a class called Print. What Print.classin return? Javier: When you write .classafter a class name , it refers to a class literal - an object that represents information about a given class .j

What does "Class<?" mean in Java?

Poplar 100 I came across this function definition: public Collection<Class<? extends SomeClass>> someFunc(); What does this Class<?part mean? Coming from C++, it looks like a template, but I'm not sure if that's the case because there are some structs in Java

Class Class [What does B mean in Java?

erotsppa: I am trying the tool jhat here to test my java memory usage. It reads in a heap dump file and prints the information as html. However, the tables look like this: Class Instance Count Total Size class [B 36585 49323821 class [Lcom.sun.mail.imap.I

Class Class [What does B mean in Java?

erotsppa: I am trying the tool jhat here to test my java memory usage. It reads in a heap dump file and prints the information as html. However, the tables look like this: Class Instance Count Total Size class [B 36585 49323821 class [Lcom.sun.mail.imap.I

Class Class [What does B mean in Java?

erotsppa: I am trying the tool jhat here to test my java memory usage. It reads in a heap dump file and prints the information as html. However, the tables look like this: Class Instance Count Total Size class [B 36585 49323821 class [Lcom.sun.mail.imap.I

What does heap initialization mean?

Isaac SEO: I did an encoding assignment for a data structure class. I'm basically going to implement different sorting algorithms (selection sort, quicksort, etc..) and compare the running times. However, different instructions, it says I have to implement two

What does variable initialization mean

username I'm reading the c++ standard and have come across this line (3.3.2/2): int x=x; In this example x, initialized with its own (indeterminate) value. is initialized xin this case ? ((Nikos Athanasiou) If you run all the checked code in VS you will get a

What does heap initialization mean?

Isaac SEO: I did an encoding assignment for a data structure class. I'm basically going to implement different sorting algorithms (selection sort, quicksort, etc..) and compare the running times. However, different instructions, it says I have to implement two

What does heap initialization mean?

Isaac SEO: I did an encoding assignment for a data structure class. I'm basically going to implement different sorting algorithms (selection sort, quicksort, etc..) and compare the running times. However, different instructions, it says I have to implement two

What does it mean to extend a static class in Java?

Yeon Ho: Looking at some Java sample code in the web, I came across the following syntax: public class WordCount { public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1);

What does this class declaration mean in Java?

ginger: I just learned about trees and what I know nothing about is the class declaration: For example: class BinarySearchTree<T extends Comparable<? super T>>. Now, can you explain what <? super T>'s in the brackets and " "? Is there any good information you

What does this class declaration mean in Java?

ginger: I just learned about trees and what I know nothing about is the class declaration: For example: class BinarySearchTree<T extends Comparable<? super T>>. Now, can you explain what <? super T>'s in the brackets and " "? Is there any good information you

What does architecture mean in a Java class file?

Brookhorn: I just built Tomcat7 and filechecked the generated class file using the command and it prints as follows output/classes/org/apache/coyote/AbstractProcessor$1.class: compiled Java class data, version 52.0 [64-bit architecture=65593] [architecture=6

What does architecture mean in a Java class file?

Brookhorn: I just built Tomcat7 and filechecked the generated class file using the command and it prints as follows output/classes/org/apache/coyote/AbstractProcessor$1.class: compiled Java class data, version 52.0 [64-bit architecture=65593] [architecture=6

What does architecture mean in a Java class file?

Brookhorn: I just built Tomcat7 and filechecked the generated class file using the command and it prints as follows output/classes/org/apache/coyote/AbstractProcessor$1.class: compiled Java class data, version 52.0 [64-bit architecture=65593] [architecture=6

What does it mean to extend a static class in Java?

Yeon Ho: Looking at some Java sample code in the web, I came across the following syntax: public class WordCount { public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1);

What does it mean to extend a static class in Java?

Yeon Ho: Looking at some Java sample code in the web, I came across the following syntax: public class WordCount { public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1);

What does this class declaration mean in Java?

ginger: I just learned about trees and what I know nothing about is the class declaration: For example: class BinarySearchTree<T extends Comparable<? super T>>. Now, can you explain what <? super T>'s in the brackets and " "? Is there any good information you