Java Glossary : java.exe

CMP home Java glossary home Menu no menu Last updated 2004-06-29 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : J words : java.exe.

java.exe
java.exe is the JVM runtime or JIT that lets you execute your class files. It comes bundled with the JDK. If you install Java 1.4.2 in the default directory you should find it in J:\j2sdk1.4.2_04\bin\java.exe. The java.exe that comes in the stripped down JRE install for end users that does not include the compiler etc. is used to be called jre.exe. In JDK 1.3+, there is only one java.exe. jre.exe is gone. For all practical purposes you can treat jre.exe as identical to java.exe. .

The key thing to understand about java.exe is that it wants the name of a class on the command line, not the name of a class file. It could have been made smart enough to eat either, but it wasn't.

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.

Long Command Lines

javac.exe has the @file.txt method to build up long command lines out of pieces. Unfortunately you can't do that with java.exe . If your command line is too long what can you do?

CLASSPATH And File Naming Recipes

Here are my simplified rules for using CLASSPATH and naming the files on the java.exe command line:
  1. Use JDK 1.1 or later. Configure your SET CLASSPATH= to clear it out. Avoid JDK 1.0 if you can because its CLASSPATH is more complicated since it has to help java find the standard classes.
  2. Download SmartJ. It forgives most problems with classpath and file naming, even if you use JDK1.1+. Unfortunately it has not been updated to work with recent versions of Java. Think of it as training wheels.
  3. In all that follows, everything is strictly case sensitive.
  4. To run a HelloWorld.class app, in the default package in C:\MyDir, use

    CD \MyDir
    java.exe -classpath . HelloWorld
    

    Note 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.

  5. To run a HelloWorld.class app, in the default package in a jar in C:\MyDir, use

    CD \MyDir
    java.exe -jar HelloWorld.jar HelloWorld
    

  6. To run a HelloWorld.class app in C:\com\mindprod\mypackage, in package com.mindprod.mypackage, use

    CD \
    java.exe -classpath . com.mindprod.mypackage.HelloWorld
    

  7. This will not work to run a HelloWorld.class app in C:\com\mindprod\mypackage, in package com.mindprod.mypackage:

    CD C:\com\mindprod\mypackage
    java.exe -classpath . com.mindprod.mypackage.HelloWorld
    

    For that to work, you must use smartj instead of java.exe.

  8. To run a HelloWorld.class app in C:\com\mindprod\mypackage, in a jar in package com.mindprod.mypackage, use

    CD \AnyDir
    java.exe -jar HelloWorld.jar com.mindprod.mypackage.HelloWorld
    

  9. If for any reason the examples shown do not work with your version of java.exe, try various combinations of com.mindprod.mypackage.HelloWorld, com/mindprod/mypackage/HelloWorld and com\mindprod\mypackage\HelloWorld.

The Java.exe Command Line

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.
-client This is the default. Use the version of the JVM optimised for client apps
-Xint Use a pure interpreter, not the Hotspot JIT.
-debug enable remote JAVA debugging.
-Xincgc Use incremental garbage collection. You avoid the pauses, but it takes 10% more overhead.
-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.
-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. Ideally this jar has a manifest which gives the master class so you don't need to specify the class name.
-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.

Parameters with Embedded Blanks

In Unix, java.exe is just a script. You can modify the way it passes parameters from the command line into the JVM by changing this line:
exec $JAVA_HOME/bin/$ARCH/$THREADS_TYPE/$PROG "$@"
Unfortunately every OS's command processor has its own way of dealing with passing parameters that contain spaces. To make matters worse, java.exe then reparses them to pass to your main method. With two cooks, much can go wrong. The easiest solution is just to avoid blanks or quotes or other suspicious characters in your parameters. Encode them as _ or some other safe character and convert them back yourself.

On windows you can enclose your blank-containing parameters in "s and they will be stripped off before your main program sees them.

Awkward Characters in Command Line Parameters

I have tested the following only in Windows 2000. You may have to experiment with your own OS to see how much of this applies.

Jars

java.exe is ever so much easier to understand and use when all the class files are inside a single jar. In that case the member names are identical to the package names. You can hide the console by using javaw.exe (java without) instead of using java.exe.

Multiple java.exes

If you do a search/filefind you will discover more copies of java.exe than you can shake a stick at. Which one gets used? It depends on your path. The one first on the path is the one that gets used, usually the one in C:\WINDOWS\system32 or C:\WINNT\system32.

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.

  1. Delete the copy of java.exe and javaw.exe in C:\WINDOWS\system32 or C:\WINNT\system32.
  2. Define a SET JAVA_HOME=C:\Program Files\Java\j2re1.4.2_04 (no quotes!) environment variable to point to the where the \bin directory is containing the java.exe you want to use.
  3. Make all references in your bat files to your JVM use %JAVA_HOME%\bin\java.exe, ditto for javaw.exe and javac.exe.
  4. Change JAVA_HOME to switch JVMs. Unfortunately, IE, Opera and Netscape won't pay any attention to you.
Instead of using java.exe repeatedly in a batch file, it is much more efficient (i.e. faster) to write a tiny Java program that just invokes the main methods of the various steps in turn. That way you only have to load the JVM once. You can use exec to handle that which you still want to do in BAT files. You are reversing the roles, Java calling BAT files rather than BAT files calling Java. You will find many task are easier in Java that BAT language.

Aborting

You can abort java.exe by hitting ctrl-C. You can abort and get a dump of what was going on at the time with the threads with Ctrl+Shift+Break. For anything fancier, you need a debugger.
Applet ¤ armouring ¤ CLASSPATH ¤ compiler ¤ console for how to deal with the problem of output scrolling off the screen before you can read it ¤ environment ¤ flipping between different JVMs ¤ Java Invoker student project ¤ javac.exe ¤ javaw.exe ¤ PATH ¤ printable ¤ properties ¤ SmartJ ¤ tools


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 12828.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/javaexe.html J:\mindprod\jgloss\javaexe.html