Lab #1
CSE110 - Arizona State University
Topics
•Setting up and using an IDE to run a basic Java Program.
This is a one-time setup and will be used for all your programs for CSE110, both the Lab and homework
assignments. These are the scenarios that are covered in this document:
1. Setup on Windows pc using TextPad
2. Setup using Eclipse for Mac or Windows and create a HelloWorld project.
Prelab
Register on the Submission Server
In order to submit your labs and assignments, you must create an account on the Submission Server by
going to the Blackboard page and clicking the “Online Submission” tab on the left. When on the site, click
on “Register” and then register with your 10-digit ASU ID (Important!!) and email address.
When you are finished with the Lab follow the instructions at the end of the Lab to submit your file to
the server.
Setup on a Windows PC using TextPad
Most of the information in this section is covered in the videos Installing JDK and Installing TextPad
under Installing JDK and an IDE on the course website.
TextPad is a basic IDE that has all we need for this class. In order to use TextPad we first must down-
load and install the Java Development Kit (JDK) which contains the tools needed to compile and execute
Java programs. Be sure to download and install the JDK before TextPad. Accept the licensing terms and
download and install the appropriate JDK for your PC from the following link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
After downloading the JDK, then you can download and install TextPad from:
http://www.textpad.com/download/index.html
After installing TextPad open the program and check that it successfully linked to the JDK you downloaded.
Do this by choosing Tools from the toolbar and scrolling down to External Tools at the bottom. You should
see three Java options when it is expanded (Compile Java, Run Java Application, Run Java Applet).
If these do not show up then you have to manually add the JDK to your computer’s system path. Fol-
low the instructions in the slides under Manually Install JDK on the course website under Installing JDK
and an IDE for the instructions to manually link the JDK.
To use TextPad to create a program first save the file with the same name as the class name as a .java
file. Then as you type the program below into TextPad, it will color code your text and indent for you.
1
When you have finished typing your program (or part of your program), then you first need to compile
your program. This is done by pressing ctrl+1 (ctrl and 1 together) or choosing Tools from the toolbar,
then External Tools and Compile Java. Then to run the compiled program press ctrl+2 or choose Tools →
External Tools →Run Java Application.
Setup using Eclipse for a Mac or PC
Most of the information in this section is covered in the video Installing Eclipse on the course website under
Installing JDK and an IDE.
TextPad only runs on Windows, so we cannot use it for Macs. Instead we will use Eclipse. Eclipse is a
larger IDE than TextPad with many more features, some of which will be helpful. Windows users may also
prefer to use Eclipse for some of the extra features.
To run Eclipse, you need to have JRE installed on your computer. Download and install the latest JRE or
JDK from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Then download and install the Eclipse IDE for Java Developers for your computer environment at the
following link:
http://www.eclipse.org/downloads
After Eclipse is installed start it up. It will ask you for a workspace to save your files. Change this to
whatever you want and pay attention to this as this is where you will find the files on your computer that
you have to submit.
After Eclipse opens you will have to create a new Java project in order to create any files. To do this
choose File →New →Project. Give the project a name and click on Finish below.
Next you have to add a Class to your Project. To do this right click on the project in the package ex-
plorer on the left of the screen and then select New →Class. Name the class the appropriate name, for
example you should call the class you create here Lab1 and click on Finish. The editor will then open and
you can type in whatever you need to finish the program.
To compile and run the program click on the green play button in the toolbar. The output will show
up in a console at the bottom of Eclipse.
2
Lab 1 - HelloWorld - First Project
1. Type the following project into your IDE adding your name and time spent. Make sure your class file
is called Lab1.java:
//***********************************************************
// Name: Your Name here
// Title: Lab1.java
// Description: Prints out My first program and my name.
// Time spent: 20 minutes
// Date: 5/15/2014
//***********************************************************
public class Lab1
{
public static void main (String[] args)
{
System.out.println("This is my first program!");
}
}
Compile and run the program. What is the output?
2. The System.out.println(" "); causes whatever is in between the " " to be printed to the console and
whatever comes next to be printed on a new line. Add another System.out.println statement in the
program above so that it will print out your name before printing out This is my first program!.
So an example output should be:
Hello, my name is Ima Student.
This is my first program!
After modifying your program, compile and run it again and check the output is correct.
3. The System.out.print(" "); command will print whatever is in between the " " but will print
whatever is next immediately after it. To see how this works, delete the "ln" from the end of the first
print statement (that prints your name) and compile and run again. Now what is the output?
4. Change the program back so you get the same output in part 2. Be sure to compile and test the
program again.
5. Submit your Lab1.java file to the Submission Server. Go to the Submission Server located on the
course website, then click on Lab Submissions in the left frame. The dropdown box will start in Lab1,
so you don’t have to change it (you will for future labs). Click on the browse button and find where
you saved your Lab1.java file (and not the Lab1.class file) on your computer. Upload the file to the
site and then click on the Submit button.
Your file will be submitted and a screen will show up displaying if your program compiled and what
your output is when run on some sample input (in this case nothing).
You should then check to make sure that the actual file submitted properly and is readable to the
grader. To do so click on Grades in the frame on the left of the page and then click on the 0 under-
neath Lab1. You will again see that your program compiled and the sample output, but you should
scroll down to the bottom of the screen and make sure your file is readable as well.
3