Welcome to Lab 1. This lab has been designed to introduce you to the CSE Windows computing environment, and to the process of writing, compiling, running, and submitting your labs. This lab has been designed with a specific set of steps for you to follow. If you have any questions or run into any trouble, please let your instructor know.
Eclipse is an integrated development environment (IDE) for the Java language (and a lot more, but we won't worry about that in CSE 201). Eclipse provides a broad variety of tools and functionality, but in CSE 201 we'll concentrate only on a subset of the functionality provided by the Java development tool (JDT) within Eclipse. Essentially, the JDT is a tool that will allows you to create, modify, maintain, organize, and run our Java programs.
Find the Eclipse shortcut on the desktop and double-click on it to start Eclipse. You will be presented with the following window.
This is an introductory screen that provides several links to more information about Eclipse. You should feel free to explore these later on, but for now, we want to move to the Java environment as soon as possible, so move the mouse to Workbench icon (the rounded arrow on the right of the window) and click on it. This will take you to the Java perspective shown below.
The Eclipse window is always organized according to a perspective. The current perspective determines the panels (views and editors) that are displayed in the Eclipse window. The default perspective when Eclipse is started for the first time is called the Java perspective which is where you will do all of your programming work for this class.
For now, just take a look around the current window: note the menubar at the top with a variety of menus (File, Edit, Help, etc.), the toolbar below it, and the various panels in the Java perspective (Package Explorer/Hierarchy, Outline, Problems/Javadoc/Declaration). This is the typical structure of most Eclipse perspectives. We'll learn more about this in the next section.
Let's start by creating a new Java project. This is always the first step in creating a new Java program. A project is like a folder collecting the files for a given program (or lab assignment).
Select File->New->Java Project.
This will open the New Java Project dialog.
Type Lab1 in the Project name box. Then click on the Finish button at the bottom. This will create the new Lab1 project.
The blank area in the center is meant for the editor which will appear when we start editing our program.
Note also that the Lab1 project you just created is listed in the Package Explorer panel on the left.
Now let's create a new Java program. Select the Lab1 project in the Package Explorer panel by clicking on it (it is probably already selected). Then select File->New->Class.
This will open the New Java Class dialog.
Type HelloWorld in the Name box. Select the checkbox next to public static void main(String[] args) to make sure a main program skeleton is created. Finally click on the Finish button. Here is what the Eclipse window will look like, note that the editor panel now displays the skeleton of our new java program.
Edit the program so that it looks exactly as the following (except for the creation date and the name of the author which you should change appropriately).
/**
* Created on Feb 21, 2005
*
* @author Paolo Bucci
*
* Simple program to print a greeting.
*/
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
Then click on the Save button at the top left of the window to save your program.
Now it's time to run your first program. Note that before running the program it is necessary to compile it. However, by default, Eclipse compiles your program after every save. So the program is already compiled and you can execute it. If you made any Java syntax mistakes in typing the program, Eclipse will list the errors in the Problems tab under the editor window. Fix them and save the program again.
To run the program, select Run->Run.
After a short time, the program will start and a new tab labeled Console will appear in the bottom pane. This is the space where you will be able to interact with your program, i.e., this is where the output of the program will be displayed and where you will be expected to type any inputs your program needs. If the Console tab is not the top one, simply click on its name and it will be brought in the foreground.
The program prints Hello world! in the Console and then terminates.
Congratulations! You have just entered, compiled, and executed your first Java program in Eclipse. Of course, there is a lot more to learn about the Eclipse environment, but you have already used most of the features that you will need in CSE 201.
In Eclipse it is very simple to print an open program or other text file: select File->Print... and in the Print dialog that appears make sure that the selected printer is one of those in the lab where you are working, and then click on the Print button. Don't forget to pick up your printout at the local printer.
In several lab assignments you will need to import some given files into your project. Let's import a file needed for this assignment.
First, make sure the src folder in the Lab1 project is selected in the Package Explorer panel (click on it if it is not). Then select File->Import.... The Import wizard appears.
Expand the General folder and select File System from the list as the import source, and click on the Next button. The next page is displayed.
In the From directory box enter K:\CSE201\Lab1 (or use the Browse... button to find the Lab1 folder nested in the CSE201 folder on disk K:). You may need to click once in the left blank box below the From directory box to make the list of available folders/files appear. Then click on the Select All button. Make sure that the Into folder box contains Lab1/src (if needed, type it or use the Browse... button to find the Lab1/src folder). Finally click on the Finish button.
After a moment, Eclipse will update the the main window. It should look something like this.
In the Package Explorer you can see the newly imported file Errors.java. The little red icon (the one that looks like an 'x') superimposed on the Lab1, src, (default package), and Errors.java entries indicates that Errors.java has some errors in it. Open Errors.java by double-clicking on its name in the Package Explorer. This opens the file in the editor.
To see a list of the errors in Errors.java, bring the Problems tab at the bottom to the front by clicking on the tab name. This is what Eclipse should look like.
As you can see, Eclipse is very helpful in pointing out syntax errors in Java programs. Not only does it list the errors in the Problems tab, but it also provides visual cues in the editor window as to where the errors are located. Note also that if you place the mouse cursor on one of the red 'x' icons on the left side of the editor window, Eclipse provides a floating message describing the error.
Well, now it's your turn. Fix all the errors in Errors.java, save it, and run it as we did with HelloWorld (see Running a Program if you don't remember how do that). What is the output?
Let's create one more program to make sure all the steps are clear.
Create a program called Multiples in the Lab1 project (see Creating a Java Program if you cannot remember how to do this).
Edit the program so that it looks exactly as the following (except for the creation date and the name of the author which you should change appropriately).
/**
* Created on Feb 21, 2005
*
* @author Paolo Bucci
*
* Multiples calculates and outputs the square and cube of a value
* it has input from the user.
*/
import java.util.Scanner;
public class Multiples
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a whole number: ");
int number = keyboard.nextInt();
System.out.println("The number is " + number);
System.out.println(
" " + number + " squared is " + number * number);
System.out.println(
" " + number + " cubed is " + number * number * number);
}
}
Fix all syntax errors, save your program, and run it several times with
different inputs. Does the program do what you expected it to do?
After you have completed the above steps in the lab, you should submit the source code contained in the files you have created.
To start the submit tool double-click on the desktop icon named Submit. This will bring up the Submit Tool window.
First, make sure that the correct Section is displayed, i.e., that the number displayed in the Section box corresponds to the call number for your section of CSE 201 (this should always be correct, but just in case...). Then select from the Assignment list the entry corresponding to the lab you are submitting (in this case lab1). The next step is to select the files you want to submit. In the top half of the Submit Files panel, find the appropriate project folder (in this case z:\eclipse\workspace\Lab1\src). Select the files you want to submit one at a time and click on the Add File button. For this lab you need to submit the following files:
Make sure you submit only these 3 files and that they are the final, correct version. Here is what the submit window should look like:
When you are satisifed that all the correct files have been included in the Submit List, click on the Submit Files button. The following confirmation dialog should appear:
If everything looks in order, click on the OK button. Another dialog confirming the submission will appear:
Click on the OK button and you're done!
To lock the screen click on the Start button in the bottom left corner of the screen, select Windows Security, and click on Lock this computer. When you are ready to resume your session just type in your password and hit return.
Logging Out: When you are done with your session you must log out. See the Logging Out for instructions. Don't leave until you have verified that you are completely logged out.
Problems with Hardware: If you have any problems with a machine or a printer make sure to ask the consultant to help you. Do not attempt to fix it yourself. Do not turn off a machine for any reason.
Printing Policy: You are only allowed to have three jobs in a printer queue at any one time. This is to be fair to other students and give them a chance to print things out. If you have more than three jobs you can send them to different printers or just send three at a time.
Do not print more than one copy of something. The printers are not to be used as copy machines. If you need to print copies just go to one of the many copy machines located all over campus.
Account Responsibility: Remember that anything that happens on your account is your responsibility. Do not let other people use your account. Make sure to either lock your screen or log out of your machine before you leave the lab. It would be easy for someone to erase all of your files or send nasty mail to someone from your unattended account.
Bitmaps: Do not display potentially offensive bitmaps (gifs, rasters, pictures, etc...) on your screen.
Academic Misconduct: All work is supposed to be done by you and only you. Consultants can help you if you have errors but they will not write your labs for you, do not ask them. Don not copy your peers labs either, consultants will be monitoring this.
For more information on official policies see the "CSE Policies" section of the CSE homepage as well as the policies appendix in the UNIX Guide for new Users (also available form the CSE homepage as "CSE Help").