How to compile and run Java program

By in Software Reviews on October 2, 2010

Java is not popular enough among normal computer users but Java get high demands from professional. Besides the language features and functionalities, Java Runtime Environment (also called Java Virtual Machine) makes software developed using Java capable for cross platform. Certain software can only run in one type of OS, but Java software can be run in most operating system such as Windows, Solaris, Linux, and Mac without altering the source code.

For end users that need to run Java program, they only need to install JRE (Java Runtime Environment) that can be get for free at Sun Microsystems Inc website. For those that want to develop Java program, then you need to install JDK (Java Development Kit).

Write, edit, and compile Java manually

Once you installed JDK, you can already begin your Java programming. You can do it using the standard Note Pad program and save the program as .java format (ex:

After that you can compile the program by using Command Prompt. Go to the directory that contain the .java file and type,


There is a high chance you will get error as Windows still doesn’t know what is ‘javac’. So you  need to set the PATH by going to Windows Properties > Advanced System Settings > Environment Variables > System Variables.


java program

In the System Variables, find Variable that is called Path and add the path to JDK bin. The path might be different depends on the version of JDK that you installed. The path should look something similar to this

C:\Program Files\Java\jdk1.6.0_21\bin;

Now try compile again (javac and you will have no error. Compiling the .java file means that the file is converted to .class that contains java byte codes.

Lastly, you can run the Java program by typing,

java filename

You don’t need to put any extension behind the filename or you will get error.

java compiler

Software environment to write, edit, and compile Java

For those that want comfortable way to write and compile Java program, then you can download software environment that supports Java development. There are numbers of software that specialized for that but I prefer Net Beans software as it is free and reliable.

If you need to build standard Java application, download Net Beans for Java SE. If you want to build web related program, then Java FX is the way to go. Besides Java, Net Beans also supports other language such as C, C++, and PHP. That’s why I love Net Bean, one for all, and all for one. Don’t need to cluster your hard disk because of installing a lot of programs.

Comments are closed.