COMS S1004 Getting Started With Java On CUNIX: Before You Start
COMS S1004 Getting Started With Java On CUNIX: Before You Start
or
pico HelloWorld.java
See below for instructions on how to use these programs.
Here is a very simple Java program (note that line numbers are not part of the program!):
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* This class just prints Hello, World. And thats it.
*/
public class HelloWorld
{
/* This is the main method. The program starts here. */
public static void main(String[] args)
{
// this is how to print something out
System.out.println(Hello, World!);
}
}
When you are done typing, save and exit the editor using the commands on the next page.
5. Compile the code
Once you have saved the file and exited the editor, you can try to compile the code with
the following command:
javac HelloWorld.java
If you dont get any messages, that means the code compiled properly! If you see error
messages, go back to Step 4 and fix them.
6. Execute the code
Once the code has properly compiled, you can execute it (run the program) as follows:
java HelloWorld
7. Logout
To terminate your session, log out like this:
logout
Thats it, youre done!
rm filename
mv old_name new_name
cp filename new_name
more filename
ls l
cd
cd ..
Ctrl-X Ctrl-S
Ctrl-X Ctrl-F
Ctrl-K
Ctrl-Y
Ctrl-X Ctrl-C
Ctrl-O
Ctrl-K
Ctrl-U
Ctrl-X