Skip to main content

Posts

Showing posts with the label JVM

Object initialization

As with class initialization, the simplest kind of object initialization is automatic initialization of object fields to default values. Example: class ObjectInitializationDemo1 { boolean b; byte by; char c; double d; float f; int i; long l; short s; String st; public static void main (String [] args) { ObjectInitializationDemo1 oid1 = new ObjectInitializationDemo1 (); System.out.println ("oid1.b = " + oid1.b); System.out.println ("oid1.by = " + oid1.by); System.out.println ("oid1.c = " + oid1.c); System.out.println ("oid1.d = " + oid1.d); System.out.println ("oid1.f = " + oid1.f); System.out.println ("oid1.i = " + oid1.i); System.out.println ("oid1.l = " + oid1.l); System.out.println ("oid1.s = " + oid1.s); System.out.println ("oid1.st = " + oid1.st); } } Output b = false by = 0 c = d = 0...

Class initialization

Although we tend to think of initialization in terms of assigning values to variables, initialization is so much more.  For example, initialization might involve opening a file and reading its contents into a memory buffer, registering a database driver, preparing a memory buffer to hold an image's contents, acquiring the resources necessary for playing a video, and so on. Java supports initialization via language features collectively known as  initializers. Class initialization is different from Object initialization and it happens before Object initialization.   Class Initialization A program contains no of classes, before the execution of java program the class loader loads the public class having the PSVM. Then the byte code verifier verifies the class. Then class initializes. The class fields are set to default values. For Example:   static boolean b;//flase static byte by;//0 static char c;// static double d;//0.0 static float f;...

Class Loading while running JVM

The Order is Bootstrap classes  - Classes that comprise the Java platform, including the classes in  rt.jar  and several other important jar files. Extension classes  - Classes that use the Java Extension mechanism. These are bundled as  .jar  files located in the extensions directory. User classes  - Classes defined by developers and third parties that do not take advantage of the extension mechanism. You identify the location of these classes using the  -classpath  option on the command line (the preferred method) or by using the CLASSPATH environment variable.