The other thing to understand is that java.exe and javac.exe were written by two different teams of people who never had coffee together. That’s why the command line switches are so infuriatingly inconsistent.
All applications that you run with java.exe (such as HelloWorld.java ) must have a
public static void main ( String[] args )method.
CD \MyDir java.exe -classpath . HelloWorldNote that the -classpath must come before the HelloWorld classname. To remember the order, you can think of it like this. java.exe needs to know the classpath before it can search for the class. If you get them reversed you will just get a mysterious NoClassDefFoundError.
CD \ java.exe -classpath . com.mindprod.mypackage.HelloWorld
CD E:\com\mindprod\mypackage java.exe -classpath . com.mindprod.mypackage.HelloWorldFor that to work, you must use smartj instead of java.exe.
REM For this to workYou must specify the class to execute, REM com.mindprod.mypackage.HelloWorld in the manifest Main-Class entry. CD \AnyDir java.exe -jar HelloWorld.jar
| Java.exe command line switches | |
|---|---|
| Option | effect |
| -help | print out info on options. Trust what it says over what I say here. Knowledge keeps no better than fish. |
| -version | print out the build version. |
| -v -verbose | turn on verbose mode. |
| -server | use the version of the JVM optimised for server apps. This only works with the private JRE java.exe that comes with the JDK in J:\Program Files\java\jdk1.6.0_06/bin/java.exe, not the public JRE in C:\Program Files\java\jre1.6.0_06/bin/java.exe. |
| -client | This is the default. Use the version of the JVM optimised for client apps |
| -Xint | Use a pure interpreter, not the Hotspot JIT. |
| -XX:+PrintOptoAssembly | Display the generated assembly code, not the byte code, the CPU-specific assembly code generated by HotSpot. |
| -debug | enable remote JAVA debugging. For ordinary debugging, you probably want -verbose or -g instead. |
| -g | include debug code to create stack traces with variable names and line numbers. |
| -javaagent:myagent.jar | define a jar containing a java.lang.instrument agent to use for monitoring code. JDK 1.5+. Note the quirky extra colon. |
| -Xincgc | Use incremental garbage collection. You have shorter pauses, but it takes 10% more overhead. |
| -XX:+UseParNewGC | Use concurrent garbage collection to avoid pauses. |
| -verbosegc | print a message when garbage collection occurs. |
| -noclassgc | disable class garbage collection. |
| -Xss64k | set the maximum native stack size for any thread, in 1024 byte chunks. |
| -Xoss300k | set the maximum Java stack size for any thread, in 1024 byte chunks. |
| -Xms4m | set the initial Java heap size, in megabytes. You can burn this, and similar java.exe
switches in at compile time with the javac.exe -J
switch. You can also put them into a SET parameter and reference them on the
command line e.g.
set jopts=-Xms4m ... java.exe %jopts% MyClass |
| -Xmx10m | set the maximum Java heap size, in megabytes. |
| -cp .;C:\java\classes.zip… | list directories in which to look for classes. It is sometimes spelled out longhand -classpath. Infuriatingly, javac.exe won’t let you use the -cp shortcut. Starting with Java 1.2 you don’t add classes.zip, (or rt.jar) to the classpath. |
| -jar C:\java\myjar.jar… | Names jar to look inside for class files. This jar jar must have a manifest Main-Class which gives the name of the class to execute. You may not specify it on the commnd line. |
| -prof:java.prof | output profiling data to .\java.prof. |
| -verify | verify all classes when read in. |
| -verifyremote | verify classes read in over the network. |
| -noverify | do not verify any class. |
| -Xfuture | Recommended to test all class files for strict conformance with coming mandatory standards. |
On windows you can enclose your blank-containing parameters in "s and they will be stripped off before your main program sees them.
java.exe -jar myjar.jar "-something"
java.exe -jar myjar.jar "new improved blue raspberry flavour"
java.exe -jar myjar.jar "She said, \"I'm leaving\"."Backslash in any other context just means plain backslash. Unlike in Java String literals, you don’t double each backslash.
java.exe -jar myjar.jar "F:\Program Files\"That is illegal! and you can’t specify it another way.
To complicate things further the java.exe in system32 is just a dummy. It looks in the registry and then decides which real java.exe to use. The last JVM installed gets to be the one used, even if it is older. To switch JVMs, you must normally reinstall the one you want.
How can you make order of this chaos and manage your choice of JVM with some finesse?
You could fiddle with the registry to switch JVMs. See the JVM Manager student project. However, there is a simpler, cruder way.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.17] | The information on this page is for non-military use only. | ||
| You are visitor number 80,492. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/javaexe.html | J:\mindprod\jgloss\javaexe.html | ||