Programming Environment


In this class, we will be using a combination of a text editor and the command line java compiler, javac, and java runtime, java. You may use any text editor you like, but the official "supported" text editor for this class is JEdit. Our default OS will be Linux. You are free to install the proper tools on your own computer, but your programs MUST compile and run on the standard lab setup.

The following is a brief tutorial to show you how to use these tools in the lab.

Step 1: Writing your programs with jEdit

jEdit is very similar to Notepad and other basic text editors. To run jEdit, simply type jedit at the Linux command prompt.

jEdit contains built-in help if you get stuck. You can also check out its web site, http://www.jedit.org.

Step 2: Compiling your programs with the Java compiler

We will be using Sun's Java compiler, javac, in this course, and compiling from the command line. The basic syntax is

> javac Class1.java Class2.java ...

where Class1.java, Class2.java are the names of the files containing your Java source code.

javac has several options that you may need to use from time to time, but most of the time you will just need to type, in the same directory as your source files, javac followed by the name(s) of your source file(s).

If you have many source files to compile, you can list the names of the files in one or more files and use this as the argument to javac. For example, if you have source files Class1.java, Class2.java, Class3.java, Class4.java, Class5.java, you can create a file, say MyClasses, that looks like this:

Class1.java
Class2.java
Class3.java
Class4.java
Class5.java

and then type at the command line:

> javac @MyClasses

The Java compiler will then compile all of the class files listed in MyClasses. If the program(s) compiled successfully, the command prompt will just return. Otherwise, you will see a list of warnings and error appear.

Once you've compiled your program files successfully, you should see a number of .class files in your working directory. In the example above, you would see Class1.class, Class2.class, etc, alongside the Class1.java, Class2.java, etc, files. These .class files are the compiled files that the computer will actually run, in the next step....

Step 3: Running your programs using the Java command line

To run your program, the command java is used. You run java on the .class file containing your main method. For example, if your main method is in the program file MyMainClass.java, you would type the following at the command line to run the program:

java MyMainClass

Do not include the .class extension here!

If there are any run-time errors, these will show up in the window from which you ran java. Repeat steps 1-3 until these errors go away.

If you are still having problems, check out this page of common errors.