User's Guide to the Java Editor

This class provides a text editor specialized for editing Java source. It is automatically invoked whenever you open any file with a .java extension. Java is an object-oriented language developed by Sun. Java is similar to C++, but Java has a few new features, such as garbage collection. Java is also missing a few features C++ has, like multiple inheritance.

The EditJava Itcl class is derived from the EditCpp Itcl class, and therefore inherits all of its features, such as invoking make. The EditJava class colors certain Java constructs, such as comments.

For more Java resources, see the Tycho Java page.

Compiling and Running Java

The Compile and Load menu choice under the File menu will compile and optionally run the Java file currently being edited. The CompileJava class documentation discusses the programming details, we discuss the user level details below.

The EditJava editor supports two primary methods of compiling Java files:

  • If the .java file contains a main(), then we call java -cs ClassName, which will check the modification times of the .java and .class file and compile if necessary. Then the class file is run and we are done.
  • If the .java file does not contain a main(), then we call javac ClassName, which will compile the file.
    After the compilation successfully completes, we check if there is a ClassName.html file present, then we run appletViewer ClassName.html. It would be nice if we checked to see if the .java file extends Applet, but that is more work.
  • CLASSPATH

    The CLASSPATH environment variable controls where the Java tools such as javac, java, and appletviewer. javac and java take a -classpath option, appletviewer does not.

    If useEnvClassPath preference is true, then the CLASSPATH is read from the user's senvironment with $env(CLASSPATH) and passed to java or javac. (The useEnvClassPath preferences and the other Java editor preferences are set in the Java preference).

    If the useEnvClassPath preference is false, then Tycho reads the classPath preference and sets the CLASSPATH environment variable before calling the Java tools.

    The javaHome preference refers to the directory that contains the Java Development Kit (JDK). The initial default of the javaHome preference is taken from the value of the JAVA_HOME environment variable.

    The javaHome preference is used to find the JDK HTML documentation for the built in Java classes. The JDK HTML documentation should be in the api subdirectory of the JDK. The location of the JDK HTML documentation is used to fix javadoc hyperlinks.

    Compiling a Java Application

    $TYCHO/editors/textedit/test/DrawTest.java is a Java application that includes a main(). If you edit this file and then invoke Compile and Load with either
  • The Compile and Load choice under the File menu.
  • By typing C-x C-r
  • then an Exec widget will come up and compile and run the Java file with java -cs -v

    Note that compiling a Java file will create a .class file in the directory where the .java file resides. If you do not have write permission to $TYCHO/editors/textedit/test then you could copy the .java files to a directory where you have write permission.

    Compiling a Java Applet

    $TYCHO/editors/textedit/test/Blink.java is a Java applet that does not include a main(). If you edit this file and then invoke Compile and Load as above, first javac is run to compile the file, and then appletviewer is run.

    Note that the Exec windows that come up when you compile a Java file are persistent between compilations. This allows you to modify the command line once and reuse your command line during the next compilation

    Special Menu choices

    The Body Template command in the Special menu places a body template at the current point in the buffer.

    The File Template command in the Special menu copies the file $TYCHO/editors/textedit/templates/JavaTemplate.java into the editor and does some substitutions described below.

    The Generate doc command in the Special menu asks the user if they would like to save the buffer and then runs the javadoc program to produce HTML documentation for the current file.

    The appletview choice in the Special menu brings up the appletviewer program and loads the file being edited into appletviewer

    Java file template substitution

    When the Java template file is substituted into a Java editor, certain substitutions occur.

    The string ClassName in the template file is substituted with a class name based on the name of the file. For example, if the file is named Elvis.java, then the class name Elvis will be substituted everywhere ClassName appears.

    The Java package is updated accordingly if the file is located in a directory below $TYCHO/java. For example, if the pathname to the file was $TYCHO/java/devel/mystuff/Elvis.java, then the package line would look like:

    package devel.mystuff;
    
    If the file is not below $TYCHO/java, then the package line is commented out.

    The @author Java doctag is updated to use the userName preference which contains the full name of the user. This preference can be updated by mousing on the Help button on the upper right of most Tycho windows and then clicking on Preferences. The userName preference is under the Miscellaneous preferences.

    Javadoc tags

    For reference, we list the javadoc tags below:
    @see classname
    javadoc will not create links in the html output for the @see tags unless javadoc is passed both the file that contains the @see and the file that is referred to.
    For example, if your class Foo.java uses @see Bar.java, then you must run javadoc Foo.java Bar.java.
    @see full.classname
    @see full.classname#method-name
    @see full.classname#method-name(first.arg.type, second.arg.type)
    White space is significant here, there must be a single space between the arguments.
    @see <a href="myfile.html">My File</a>
    @version text
    The @version tag may only be used before a class definition. Call javadoc with the -version flag to generate an version listing in the HTML file.
    @author text
    The @author tag may only be used before a class definition. Call javadoc with the -author flag to generate an author listing in the HTML file.
    @param parameter-name description
    May only be used before a method definition.
    @return description
    May only be used before a method definition.
    @exception full-classname description
    May only be used before a method definition.
    @deprecated description
    This tag marks a method as being deprecated (not to be used). This tag is in JDK1.1 and later. Note that the @deprecated tag is noticed by the Java compiler. If it is present, then the compiler will not warn about a method that overrides a deprecated parent method.
    The description should be of the form
    As of version xxx, replaced by newmethod()
    See The JDK1.1 deprecation page for more information.
    @since text
    Adds a Since tag. The text need not have any particular structure.

    Tycho Home Page


    Copyright © 1996-1998, The Regents of the University of California. All rights reserved.
    Last updated: 06/08/98, comments to: tycho@eecs.berkeley.edu