Here, I was trying to implement a singleton class for my Database connectivity using the inner static helper class :
package com.myapp.modellayer;
public class DatabaseConnection {
private DatabaseConnection() {
//JDBC code...
}
private static class ConnectionHelper {
// Instantiating the outer class
private static final DatabaseConnection INSTANCE = new DatabaseConnection();
}
public static DatabaseConnection getInstance() {
return ConnectionHelper.INSTANCE;
}
}
However, my doubt is when does this static inner class, ConnectionHelper, gets loaded in to the JVM memory:
At time when DatabaseConnection class gets loaded, or At a time when getInstance() method is called ?
static class
does not have the same meaning as static in a member declaration in Java. It simply means it is a nested non-inner class. – Neutralism