You need to set up your environment to use Java properly. Make sure javac and java are in your command path. Use the editor of your choice, but preferably XEmacs!
Create a directory javacourse (or some such) for this course.
/**
* A class that prints out Hello World.
*
* @author (c) everyone who ever wrote a program, beginning of time
* @version 1.0
*
**/
class HelloWorld
{
public static void main( String args[] )
{
System.out.println( "Hello World!" );
}
}
Save this as HelloWorld.java (case is important)
Java code has to finish with the extension .java, and each public class has to be stored in a seperate file of that name.
It is 'compiled' (to the virtual machine code in HelloWorld.class)
by the command
javac filename.java
This has been mapped to the key sequence C-c C-v C-c in the Emacs editor (Pulldown menu JDE/Compile).
Run it in a command shell with
java HelloWorld
Alternatively, you can run it in Emacs using the the key sequence C-c C-v C-r (Pulldown menu JDE/RunApp).
Your first Java program!
All the Java classes are well-documented online, in the standard form generated by javadoc. Check it out here - you might like to bookmark this as you'll use it a lot.
© 2001 Mark Ryan and Alan Sexton