Get the number of classes loaded by the VM

With JDK 1.5 java.lang.management package:

Main.java:

import java.lang.management.*;
 
public class Main
{
   public static void main(String []args) {
      ClassLoadingMBean mbean = ManagementFactory.getClassLoadingMBean();
      int currentlyLoaded = mbean.getLoadedClassCount();      
      
      System.out.println("Currently loaded classes: " + currentlyLoaded);      
   }
}

outputs:

Currently loaded classes: 9