How to Use the java Command
The java command runs a Java program from a command prompt. The basic syntax is
java filename [options]
When you run the java command, the JRE is loaded along with the class you specify. Then, the main method of that class is executed.
Here’s an example that runs a program named HelloApp:
C:\java\samples>java HelloApp
The bold indicates the part you type.
The class must be contained in a file with the same name as the class, and its filename must have the extension .class. You typically don’t have to worry about the name of the class file because it’s created automatically when you compile the program with the javac command.
The Java runtime command lets you specify options that can influence its behavior.
| Option | Description |
|---|---|
| -? or -help | Lists standard options |
| -classpath directories and archives | Lists the directories or JAR or Zip archive files used to search for class files |
| -client | Runs the client virtual machine |
| -cp <search path> | Does the same thing as -classpath |
| -D name=value | Sets a system property |
| -dsa or -disablesystemassertions | Disables system assertions |
| -ea classes or packages | Enables assertions for the specified classes or packages |
| -ea or -enableassertions | Enables the assert command |
| -esa or -enablesystemassertions | Enables system assertions |
| -server | Runs the server virtual machine, which is optimized for server systems |
| -showversion | Displays the JRE version number and then continues |
| -verbose | Enables verbose output, which displays more comprehensive messages |
| -version | Displays the JRE version number and then stops |
| -X | Lists nonstandard options |









