Getting Started with Java Programming for Windows Users
Installation of Java
- Download JDK 8 Update 45 from the
Java Download site.
- Accept the License Agreement.
- Download Windows Offline Installation and save the .exe file
on your desk top. (This will take some time.)
- Double click on the icon of the .exe file that you just downloaded.
- Accept the License Agreement.
- Accept the default options given to you until you get to the
Finish button. Your installation is complete.
Setting up the Environment
- Starting at My Computer go to the following directory
C:\Program Files\Java. There should be a folder starting with jdk1.8.
Click on that folder. Click on the folder called bin.
- Copy that address starting with C: and ending with bin
and close that window.
- Click on Start. Right Click on My Computer.
- Click on Properties. Click on Advanced.
- Click on Environment Variables.
- Under System Variables search for the variable Path.
- Select Path by clicking on it. Click on Edit.
- Scroll all the way to the right of the field called Variable
value using the right arrow.
- Add a semi-colon (;) to the end and paste the path (to the Java bin
folder) that you previously copied. Click OK.
- Search for CLASSPATH in your list of System Variables. If it
does not exist click on New.
- Enter CLASSPATH for the field Variable name
- Enter .; for the field Variable value. Click OK.
- If the variable CLASSPATH already exists, click Edit.
- In the field Variable value scroll all the way to the left using
the left arrow. Insert .; if that is not there already. Click OK
- Click OK until all the windows close. You have successfully
set up the computing environment.
Writing Your First Java Program
- Create a folder called CS312 on your C:\ drive. You
will be storing all your Java programs in this folder.
- Go to Start and click on Run.
- Type in notepad in the field called Open.
- In Notepad type in the following program exactly as written:
public class Hello
{
public static void main (String[] args)
{
System.out.println ("Hello World!");
}
}
- Go to File and click on Save as.
- In the field Save in browse for the C: drive and then
select the folder CS312.
- For the field File name remove everything that is there
and type in Hello.java.
- In the field Save as type select All Files
- Click on Save. You have just created your first Java program.
Running Your First Program
- Go to Start and click on Run.
- Type cmd in the Open field and click OK.
- A dark window will appear. Type cd C:\ and hit the key Enter.
- If you type dir you will get a listing of all folders in
your C: drive. You should see the folder CS312 that you
created.
- Type cd CS312 and hit Enter. It should take you to the
CS312 folder.
- Type dir and you should see the file Hello.java.
- To compile the program, type javac Hello.java and hit Enter.
- Type dir and you will see a file called Hello.class.
- To run the program, type java Hello and hit Enter.
- You should see the line Hello World!
- Congratulations, you have run your first Java program.
Getting Started with Java Programming for Mac Users
The good news is that you can skip the installation of Java and
setting up the environment if you have Mac OS 10.4 or later.
Writing Your First Java Program
- Click on File and then New Finder Window.
- Click on Documents.
- Click on File and then New Folder.
- Call the folder CS312. You will be storing all class related
programs there.
- Click on Applications and then TextEdit.
- Click on TextEdit on the menu bar and select Preferences.
- Select Plain Text.
- In the empty TextEdit window type in the following program, exactly
as given:
public class Hello
{
public static void main (String[] args)
{
System.out.println ("Hello World!");
}
}
- From the File menu in TextEdit click on Save As.
- In the field Save As: type Hello.java.
- Select Documents and the file folder CS312.
- Click Save.
Running Your First Program
- Select Applications, then Utilities and Terminal.
- In your Terminal window type ls and Return. It should
give a listing of all the top level folders. You should see the
Documents folder.
- Type cd Documents and hit Return.
- Type ls and hit Return and you should see the folder CS312.
- Type cd CS312 and hit Return.
- Type ls and hit return and you should see the file
Hello.java.
- To compile the program, type javac Hello.java and hit Return.
- Type ls and you will see a file called Hello.class.
- To run the program, type java Hello and hit Return.
- You should see the line Hello World!
- Congratulations, you have run your first Java program.