class MySpecialObject { // Space for this variable is allocated on the heap. int a; } // In fact, space for the whole object instance is allocated on the heap. public class VariableExamples { // Static variable allocated in global area. static int b = 1; // NOTE: parameter variable argv public static void main (String[] argv) { // Local variable 'c' allocated on the stack. int c = 2; // The value in 'c' gets copied into the parameter variable (see below). print (c); // Space for the whole object is allocated on the heap. MySpecialObject obj = new MySpecialObject (); // Access variables inside the object via variable name and '.' operator. obj.a = 3; print (obj.a); // When the method exits, 'c' and 'obj' both disappear. } // Parameter variable x is on the stack. static void print (int x) { System.out.println ("x=" + x); // You can treat the parameter like any variable. x = 4; // Static variable 'b' is accessible here. System.out.println ("b=" + b); // When the method exits, 'x' disappears. } }