This tutorial assumes that you have already completed the software install. If you haven't done this, go back and do so now.
Before doing anything else, go to "Documents" (or wherever you normally store your files) and create a folder called CS120
. All of your work for the course will go inside subdirectories within this folder. Inside your CS120
folder, create another folder called hwk0
. Whenever you start a new program, create a new folder for it inside CS120
, to keep your files well-organized. Here is an article on creating folders and organizing files on Mac OS X.
Open up BBEdit with a new document. Go to the hwk0
folder you previously created, and save the document as HelloWorld.java
(there should be no spaces, and uppercase versus lowercase has to be exact). Type in the source code given below exactly. Java is case sensitive, meaning you need to be careful to have uppercase and lowercase precisely as I have it below. The indentation on the left hand side is done using the tab key (one tab on the "public static" line, two tabs on the "System.out" line).
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world!"); } }
Next you will compile and run your program.
.java
file from BBEdit.view
menu of BBEdit and selecting Terminal
(the shortcut for this is holding down the 2 buttons to the left of the space bar and pressing the letter O key).javac HelloWorld.java
, since HelloWorld.java
is the name of your Java source code file. If you ever have multiple files to compile, you can use javac *.java
to compile everything in that directory.java HelloWorld
, and notice that we don't put in the .java
part this time.Once your program runs, you should see some text that greets you. There's your first Java program! Next you will need to hand it in.
HelloWorld.java
, which is your source code file (not HelloWorld.class
).