Java and JDK Basics

Com 3118 – Spring 2001

The Java Development Kit is the software package that enables a programmer to make use of the Java language. Version 1.3 of the language is due to be released very soon; a stable beta version of 1.3 is available now for registered developers. All versions of the JDK contain the same things: two compilers, one interpreter, and a host of class libraries called packages. The JDK comes with an installer that extracts all of the necessary files and changes the operating system environment to facilitate the compilation process.

Kawa is a low-cost Integrated Development Environment that provides a graphical interface for the JDK compilation-interpretation process. Visually it resembles Microsoft Visual C++, but internally it has no resemblance whatsoever. Kawa uses neither a proprietary compiler nor proprietary class libraries. Although Kawa has less overall functionality than an enterprise level IDE, it is consistent with the Java standard and is easily upgradeable to keep up with language changes. Support will be provided for the use of the Kawa IDE, which is publicly available on the NT machines in 229 Cullinane.

Projects

Kawa uses project files to organize the source files encompassing a Java "program." A Kawa project file has the extension .kawa. A project file will accompany each laboratory assignment. To add files to a project in Kawa, choose "Add file" from the "Project" menu. Project files may have advanced options and configurations, but these things are not important to the scope of the course and will be done for you in almost every case.

Compilation

The Java compiler provided in the JDK is javac, which accepts one or more Java source files and outputs one or more corresponding Java class files. Java source files are plaintext and must be named ClassName.java, where ClassName is the identifier for the public class held in the source file. Java class files are in Java bytecode format, and are named ClassName.class, where ClassName is the identifier of the compiled public class. You will not have to name Java class files, as they are created automatically from the compilation process.

There are many options and parameters that can be specified at the command line when using javac. For more information try javac –help, or consult the JDK documentation or Sun’s Java web site. Kawa automatically generates a proper command line for compilation.

Within Kawa, you can compile the currently open source file by choosing "Compile" from the "Build" menu, or by pressing the F7 key. You can compile all of the source files in the current project directory by choosing "Compile *.java" from the "Build" menu.

 

 

 

Documentation Compilation

The JDK provides a documentation compiler named javadoc, which extracts embedded comments from Java source files and produces formatted HTML documentation. It is standard practice to include embedded comments, called javadoc comments, in every Java source file.

It is part of the requirements for the course that you learn how to write

javadoc comments and do so for every class written for every assignment.

A javadoc comment is a block comment that begins with the prefix /** and ends with the suffix */. Everything contained within a javadoc comment is treated as HTML code, so it is common to mark up documentation with HTML tags such as <CODE></CODE> for bits of code and class names, <I></I> for citations of code copied from other source files, and any other tags that are appropriate to the documentation task at hand. Javadoc comments also contain javadoc tags that are extracted and used in the formatting of the output documentation. In this course, you are required to provide a javadoc comment for each class, each data member of a class, and each method of a class.

The following is the format of a javadoc comment for a class:

/**

* Description of the form, behavior, and implementation details

* for the class.

*

* @author Author’s name

* @version Date last modified

*/

public class Foo extends Bar {}

The following is the format of a javadoc comment for a data member:

/** description of the use of the data member */

public int dataMember = 0;

The following is the format of a javadoc comment for a method:

/**

* Description of the programming task performed by this method.

*

* @since Date added to class

* @param p1 description of parameter p1

* @return description of the value returned by this method

*/

public int method(Parameter p1) {}

Note that there should be one @param tag for each parameter in the parameter list for a method. A method that has a return type of void should not have a @return tag.

There are many other javadoc tags that can be included in these comments, some of which you will see later in the course. You are only required to include the above tags in your documentation of assignments for this course.

There are many options and parameters that can be specified at the command line when using javadoc. For more information try javadoc –help, or consult the JDK documentation or Sun’s Java web site. Kawa automatically generates a proper command line for documentation compilation.

Within Kawa, you can compile the documentation for one source file by choosing "JavaDoc" from the "Build" menu. You can compile the documentation for all source files in the current project directory by choosing "JavaDoc folder" from the "Build" menu. You can compile the documentation for all source files in the project by choosing "JavaDoc all" from the "Build" menu. The project files provided for this course will place compiled documentation in the /docs/ directory relative to the current project directory.

The javadoc documentation for the packages provided in the JDK is available on Sun’s Java web site. If you are going to be writing java programs on your own machine, you may want to download the documentation to your machine. It is against copyright laws to provide the documentation on a public machine, so the NT machines in 229 Cullinane do not have this documentation installed locally.

Interpretation

The JDK provides a Java bytecode interpreter named java, that "runs" the mini-program contained within the public static void main(String[] args) method of a class. Classes that are required for the program are located and used on an as-needed basis. If a required Java class file is missing, you will be notified through a runtime error.

There are many options and parameters that can be specified at the command line when using java. For more information try java –help, or consult the JDK documentation or Sun’s Java web site. Kawa automatically generates a proper command line for interpretation. To choose the class whose main method should be run, choose "Interpreter Options" on the "Project" menu and change the option "Java class name to run."

Within Kawa, you can run the main method of the main class for a project by choosing "Run" from the "Build" menu, or by pressing F4. Kawa should automatically compile any source files that have been changed since the last time the project was run. If you are getting strange errors, or if changes you make do not seem to have an effect, choose "Compile *.java" from the "Build" menu before running the program.