Please send all questions & assignments to:
dsolarek@eng.utoledo.edu

 

javac & java
The Java Compiler & Interpreter

Java Development Kit

The Java Development Kit has been installed on the class server. It contains a variety of tools and Java development information. The following list indicates the main components of the JDK:
  • Runtime interpreter
  • Compiler
  • Applet viewer
  • Debugger
  • Class file disassembler
  • Header and stub file generator
  • Documentation generator
  • Archiver
  • Digital signer
  • Remote Method Invocation tools
  • Sample demos and source code
  • API source code
We will focus our attention on the first two items: the compiler and interpreter. The runtime interpreter is the core runtime module for the Java system. The compiler, applet viewer, debugger, class file disassembler, header and stub file generator, and documentation generator are the primary tools used by Java developers.

Compiling Your Program

The Java compiler (javac) is used to compile Java source code files into executable Java bytecode classes. In Java, source code files have the extension .java. The Java compiler takes files with this extension and generates executable class files with the .class extension. The compiler creates one class file for each class defined in a source file. This means that it is possible for a single Java source code file to compile into multiple executable class files. When this happens, it means that the source file contains multiple class definitions.

Even though Java source files and classes are typically given the extensions .java and .class, it is important to note that some operating systems are not capable of fully representing these extensions because of their length. For example, Windows 3.1 is limited to three-character extensions, so Java source files and classes must use the extensions .jav and .cla.

The Java compiler is a command-line utility that works in a manner similar to the Java runtime interpreter. The syntax for the Java compiler follows:

 javac Options SourceFilename.extension
The Filename argument specifies the name of the source code file you want to compile. The Options argument specifies options related to how the compiler creates the executable Java classes. To compile the program which calculates the area of a circle, we would use the folloeing command:
 javac CircleThree.java
This would create a file named CircleThree.class which can then be run using the Java interpreter.

The table below lists the command line options that are available for the Java compiler.

OptionDescription
-classpath pathDetermines the path in which the compiler looks for classes.
-d directoryDetermines the directory in which javac stores the output files.
-deprecationProvides details about program statements and objects which have been deprecated in newer standards.
-gTells javac to create debugging information, which is used by debugging tools.
-nowarnTells javac not to display warnings as it compiles a file.
-OTells java to optimize the compiled program.
-verboseTells javac to display status information as it works.

Running Your Program

The Java runtime interpreter (java) is used to run standalone Java executable programs in compiled, bytecode format. The runtime interpreter acts as a command-line tool for running Java programs that are either nongraphical or that manage their own window frame (applications); graphical programs requiring the display support of a Web browser (applets) are executed entirely within a browser. The syntax for using the runtime interpreter is illustrated below:
 java Options ClassName Arguments
The ClassName argument specifies the filename of the class you want to execute. If the class resides in a package, you must fully qualify the name. For example, if you want to run a class called Circle that is located in a package called FindArea, you execute it in the interpreter as follows:
 java FindArea.Circle
When the Java interpreter executes a class, what it is really doing is executing the main() method of the class. The interpreter exits when the main() method and any threads created by it are finished executing. You need not worry if you are not yet familiar with the main() method or Java threads ... they are not critical to understanding the runtime interpreter at this point. The main() method accepts a list of arguments that can be used to control the program. The Arguments argument to the interpreter specifies the arguments passed into the main() method. For example, if you have a Java class called TextFormater that performs some kind of formating on a text file, you would likely pass the name of the file as an argument, like this:
 java TextFormater MyFile.txt
The Options argument specifies options related to how the runtime interpreter executes the Java program. Please refer to the JDK documentation for more information about the options supported in the runtime interpreter.
    Click on the button at left to return to the calling page.

 

There have been visitors since 11/26/2003

Added to the Web: October 30, 1999.
Last updated: October 30, 1999.
Web page design by Dan Solarek.

http://cset.sp.utoledo.edu/cset4250/