Saturday, April 28, 2012

OutOfMemoryError vs StackOverflowError

OutOfMemoryError:
Thrown when Java is running out of memory and cannot allocate any more memory in the heap for the object

StackOverflowError:
The stack space lives at the top-end of the address space and the heap lives at the bottom-end of the address space. As stack grows, it grows downwards. As heap grows, it grows upwards. So there is a potential that the two can collide and when that happens, you get a StackOverflowError thrown. Typically happens when you call some methods recursively (that keeps going-and-going).


Sunday, April 15, 2012

Command Line Arguments


packageorg.training.fundementals;

public class Args {

      /**
       * @param args
       */
      public static void main(String[] args) {
     
            System.out.println(args[0]);
            System.out.println(args[1]);
            System.out.println(args[2]);
            System.out.println(args[3]);
System.out.println(args[3]);
System.out.println(args[3]);

           

      }

}

C:\> java Args This is a simple Java program
Output:
This
is
a
simple
Java
Program