JDE Tutorial

This tutorial will walk you though the process of creating and running a program using emacs and the Java Development Environment (JDE). The first thing to do is run emacs. If you are at a work station open a teminal and type:
emacs &
If you are working elsewhere using telnet type the following:
TERM=vt100
emacs -nw
Each action you can take in emacs can be done by typing at the keyboard or often by use of menus. Both options will be discussed in the tutorial. Keyboard commands will often have special notation:
C-x Indicates that you should hold down the Control (Ctrl) key while pressing the x.
M-x Indicates that you should press the Meta key with the x. This can be done in two ways. Either press and hold the diamond key (on either side of the space bar on a sun) while pressing the x or press the Escape (Esc) key release it and then press the x.
A sequence of commands starting with a control or meta key will appear in the last line of the emacs window which is called the minibuffer. Important: anytime you find yourself typing in the minibuffer when you would rather not be, type C-g (control g) to "quit" the minibuffer. You may need to do this more than once.

Text listed with a blue background indicates text you should type in emacs. These will indicate the keyboard method for executing commands. A description of the mouse/menu method will appear nearby.

The big window in emacs is called the buffer. It is where you edit your files. Each file you have open will have its own buffer.


Creating and Opening a file

The first step to writing a program is creating a file. You can create an empty file or open an existing file using the command sequence C-x C-f (remember that is a Control x followed by a Control f). There will be a line in the minibuffer asking you to type a name for this file. If the file name exists the file will be opened. Otherwise, a new blank buffer will be opened with that filename. The file will not be created until you save (see below).

Creating a file with JDE

For the purposes of this tutorial we will use a slightly different command. We want JDE to build an outline of our program for use. So we will use the following command:

M-x jde-gen-console-buffer  

Before continuing let's break this command down into its component parts:

M-x
Either the diamond with the x key or escape followed by the x key. This will put your cursor into the minibuffer. This tells emacs you are about to give it a command.
jde-gen-console-buffer
You will type this command directly into the minibuffer and press the return key. A bit wordy. Read on.
If you are fortunate enough to be using emacs directly on a workstation i.e. you did not telnet from off site, then you can use your mouse instead. Just go to the Files menu select the JDE-New sub-menu and choose Console... We will indicate this action with the notation Files-> JDE New-> Console...

Once you have executed the command you will type the name of your new program in the minibuffer. Type Hello.java in the minibuffer and hit return. You should have in your emacs window something that looks like this: (your colors may be different or non-existent depending on how you started emacs)


/**
 * Hello.java
 *
 *
 * Created: Wed Jan 10 11:22:59 2001
 *
 * @author <a href="mailto: "</a>
 * @version
 */

public class Hello{
    public Hello (){
        
    }
    
    public static void main(String[] args){
        
    }
} // Hello

Let's make some changes to the file. Above the minibuffer is an inverse video status line which includes the name of the file you are editing and some various other information. One piece of information is the current line number--the line in your file where the cursor is currently located. You can either use the arrow keys or the mouse to move this cursor. Put the cursor on line 18 of Hello.java. That should be the blank line directly below public static void main(String[] args){. Type the following:
        System.out.println("Hello World")   //a line with an error
Line the 'S' in System up with the 'i' in public of the previous line--this is not a requirement, but it is considered good programming style. You can do this by pressing Tab anywhere on the line.  Notice that there is no semi-colon at the end of the line. This will cause a problem with the Java compiler. We want it to.


Saving

Look again at the status bar at the bottom of emacs. Notice the left end looks like --\**. The stars indicate that this file is in need of saving. To save the contents of this buffer to the current filename type C-x C-s. If you wanted to change the file name (Save As...) you would type C-x C-w and type in a new name. You could perform these tasks similarly with a mouse by using the menus Files-> Save Buffer and Files-> Save Buffer As...

Recalling or Reopening a Previously Created File

Suppose you are working on Hello.java and you want to take a break (see Quitting below). So you leave emacs and log out of your work station and leave. When you come back and restart emacs, you only need to open the file you were working on. If you are simply working on a file that already exists you can type C-x C-f or use the menus Files-> Open File... This will prompt you for a file name in the minibuffer. Try it: Emacs now has Hello.java in an open buffer, ready for you to continue.

Compiling and Fixing Errors

Now we want to compile the file Hello.java. So we will tell emacs to run the java compiler. We can do this by typing C-c C-v C-c or by selecting the menu JDE-> Compile. This action will split our window into two separate buffers. In the top you will see Hello.java. In the bottom you will see the results of the compilation which should look something like this:
cd c:/My Documents/java/
javac  -g Hello.java
Hello.java:18: ';' expected
        System.out.println("Hello World")  //a line with an error
                                         ^
1 error

Compilation exited abnormally with code 1 at Wed Jan 10 14:13:08
This shows us one error message. Each error message tells us the file name where the error is, what line number it occurs in, a description of the error and the line itself. A ^ symbol beneath the line indicates where the compiler thinks the error occurred.

Now we have two buffers showing us information. To switch between them we can either click with the mouse or type C-x o to move the cursor to the other buffer. We'll try this out later.

With JDE you can use the error messages to go directly to the line where the error occurred. Use one of the following options to do this.

Fix the error in Hello.java by adding a semicolon ; after the ) of line 18. It should now read:
System.out.println("Hello World");  //a line with an error
Recompile Hello.java with C-c C-v C-c. There will be a question in the minibuffer asking if you want to save your changes to the file. Type y.

Working with multiple buffers

Before going any further let's look at using multiple buffers. The area containing a buffer is called a window. Currently you should have two visible windows in emacs. We already saw how C-x o switches the cursor between windows. There are a number of other useful commands for multiple windows. Below are descriptions of each and how to perform them using either the keyboard or the mouse.
Description Keyboard Mouse
Move the cursor to a different window. C-x o Click in the window where you want the cursor
Go back to a single window. C-x 1 Select from the menus Files-> One Window
Split one window into two. C-x 2 Menu: Files-> Split Window

You can also have multiple buffers open at once and they don't all have to be displayed in emacs. Below are some actions for looking at other buffers.
Description Keyboard Mouse
Show all open buffers. C-x C-b Buffers-> List All Buffers. The Buffers menu has list list of the buffers you have used most recently.
Switch to a buffer from the list of all buffers. Move the cursor to the buffer name. Hit return. Click with the middle button on the name of the buffer.
Switch to a buffer without looking at the list. C-x b The name shown in the minibuffer is the default. To switch to it press return, otherwise type the name of the buffer you wish to switch to. Select the name of a buffer from those in the Buffers menu

Try it: Manipulating Buffers


Running your program

Now that we've compiled a working version of Hello.java, it's time to run our program. Either type C-c C-v C-r or select the menu JDE-> Run App. As a result emacs split your window and wrote "Hello World" to the screen, along with some other status messages which are NOT part of your program itself. 

Quitting

You can now exit emacs by typing C-x C-c or selecting Files-> Exit Emacs. 

Last modified: 01/21/03