Java compile FAQ: How do I compile my first Java program?
To compile a Java program you first need to download a Java development kit (see java.sun.com) if you don't already have one. Next, assuming you have a program named
MyProgram.java that you want to compile, you compile it like this with the
Assuming that there are no errors, this will create a file named
MyProgram.class. This file contains the Java bytecode representing the instructions of your program.
Once you've compiled your Java program, you can execute (run) the program using the Java interpreter, also known as the Java Virtual Machine (JVM), like this:
Okay, you're thinking, that seems pretty easy ... anything else I should know?
Yes, learn the options of the
java commands. One option common to both is the
-verbose option. Here's an example:
java -verbose MyProgram
Seeing through this output will help you understand what the JVM is doing for you.