You must have the Developer tools installed, or the java compiler.
Create a text file with that code.
Save as Javafun.java
In the terminal, navigate to the directory containing the java file(cd path_to_file)
type in javac Javafun.java to compile to java bytecode.
type "java Javafun: to run it, and be prepared to see it print out the numbers 0 to 999999
You must note the file name. Java files must have the file name that exactly matches the class name.