At the pegasus prompt, type emacs and ENTER. Type in the program exactly as you'd like it to appear. Type CONTROL-X CONTROL-S to save your file (save as PROGRAM_NAME.java, typically), and type CONTROL-X CONTROL-C to exit emacs.
Type javac PROGRAM_NAME.java and ENTER.
If there are no error messages, then type java PROGRAM_NAME and ENTER to run your java program.
For example, for the java program file Hello.java, type
javac Hello.java ENTER
to compile, and then
java
Hello ENTER
to run the program.