This lab is intended to be a bit of a review of the things that you've done in CS 150 and to introduce you to some new tools. At the end of this lab you should be able to:
NOTE: This lab exists outside of the usual late deadlines. If you run into problems you can get help with the rest of it during the lab times next week without expending one of your late days.
If you weren't registered for a CS class at the start of the semester, you will need to go and see Jackie Fortino in King 223 about getting building access for the semester. You should do this now, before you forget!
If you don't have a CS account, see Chris Mohler in the OCTET office (Mudd 052) about getting one.
Go to one of the CS computer labs and log in to a computer. The labs are in King 201 and King 135. You should have gotten the door code from your CS professor on the first day of class. For the most part we will use room 201 unless the class becomes too large.
Once you have logged in, make yourself a directory to put your class work in. Using a Terminal application:
% cd % mkdir cs151 % cd cs151 % mkdir lab0 % cd lab0
You should do this for each lab, not only because it organizes your files, but also because it causes less problems with handin. And you don't want any problems with handin.
Now you should start eclipse. Eclipse is a Java IDE (Integrated Development Environment) that is used world-wide. It has a number of very useful features including automatic compilation, error detection, built-in debugger, autocomplete, and many other features.
Eclipse is also available for free for your home machine, should you want some alone-time with it. Just go to the eclipse website for download.
Just run it from the command line.
% eclipse &
Alternatively, choose it from the graphical Development menu.
When eclipse starts up, it will ask you for the name of a workspace. You should just accept the default for workspace (usually ~/eclipse-workspace/). Don't select your csci151 folder as your default workspace. It'll take a little time to start up.
From the Eclipse Welcome page, click Tutorials > Create a Hello World Application. Follow the instructions to make your very first eclipse Java program. Enjoy.
Until you get more familiar with eclipse and figure things out on your own, please make the following changes to your preferences to make life easier. Start by selecting the menu Window > Preferences (On a Mac, it is located in Eclipse > Preferences.
First, let's deal with auto-completion and cursors. Click on the triangles in front of Java, Editor and click on Typing.
Notice that Eclipse will automatically insert closing braces, quotes, and the like by default. I recommend that you keep these enabled. It will take a little getting used to, but prevents annoying little bugs.
The second section "automatically insert at correct position" has things that I really like to enable. When you type either ; or a brace, it'll jump to the right spot for it most of the time. It's pretty nifty, try it out!
By default, Eclipse uses tabs for indentation. However, it displays them as being only 4 spaces, when most other applications will display them as 8. A minor detail, but changing this will make things much more readable outside of Eclipse. The easiest way is to go to Java > Code Style > Formatter and then select Java conventions as the Active profile. If you change only one setting, make it this one!
You can also get Eclipse to reformat your code when you are working on it in a number of ways. You can highlight a section of text and then hit "ctrl-I" or use the menu "Source", "Correct Indentation". You can also use the "Source", "Format" command to make similar changes. You can also have it automatically reformat your code each time you save. Go to Java > Editor >Save Actions and check the boxes marked "Perform the selected actions on save" and "Format source code". You can have it just reformat the sections of code you have been working on, or you can have it take care of the entire file.
If you take advantage of the auto-Javadoc comments, you'll probably want to also change the pattern under Java > Code style > Code Templates > Comments > Overriding methods to match the one for Methods. (Just copy the Pattern window contents from "Methods" to "Overriding methods".)
Eclipse likes to put the *.class files in a different folder than your *.java files. However, this makes it a bit harder to go between Eclipse and a normal editor. Change the preferences by selecting Java > Build Path and change the value of the Source and output folder radio button to be Project instead of Folders. Do not change the value of Source folder from src or Output folder from bin -- change the radio button only. If you change only two settings, do this one too!
While you are working in eclipse, you'll probably find that there are some functions you might want to use via the pull down menus. Note that the keyboard shortcuts are listed on the right hand side. Learning to use them will speed up your work.
Here's a list of a few such features and shortcuts:
Now you should create a project in your lab0 folder as you'll be doing in many of the labs.
If you want, you can close the Task List and Outline panes on the right side. You won't be using them for this lab.
Now, write a program that will tell the user a little bit about
yourself. In eclipse, you start by creating a new class, as
You should now see Hello151.java in the Package Explorer window. If you do an ls on the command line in your lab0 folder, you'll see that the files Hello151.java and Hello151.class are now in this folder. Eclipse compiles as you work!
The Hello151.java file should be open in the editor. If not, just double click on it in the Package Explorer window. Let's add some comments to the top of the file.
Just in case you haven't actually tried to run your program yet, now would be a great time to check that it works. Here's a line you can add to the main method that will give you some output
System.out.println("I love Java.");
You can run it in Eclipse by just selecting Run > Run
from the pull-down menus. Or right-click and select Run
As > Java Application. You should see the program
output in the Console panel at the bottom of the Eclipse
You can also run your program outside of Eclipse, by running it
from a command line, as follows:
If that didn't work, and you see that you have bin and src
folders in your cs151/lab0 folder, you missed one of the important
graders will be running your program from the command line, so
it's important that you run your program this way before
Now let's add some print statements to introduce yourself to the graders. Inside the main() method, add in a number of System.out.println messages that will share:
If you've made it this far, and actually changed preferences and done the steps I listed above, that's enough Java programming for this week.
For this class, we'll be exercising more than the usual amount of memory in Java programs. You will become familiar with the -X family of arguments to use with Java.
% java -Xmx1g MyProg # use up to 1 gigabyte of memory % java -Xmx500m MyProg # use up to 500 megabytes of memory
You probably won't need to do this on the lab machines, but you
might on your own laptop.
The CS server will be making periodic backups of your files for
you. You can access these backups in the folder
This is an exact copy of your files at the time the snapshot was made. It'll be useful if you accidentally delete something in lab. Currently only the daily snapshots are working (taken at midnight each night), but hopefully we'll have some that are more frequent as the semester progresses.
handin is the right way to submit your work in this class. If you talk to other students, they might tell you about a web based version of handin. Please don't use this as it is unsupported and has resulted in more than one student submission being discarded.
Also, always use lshand to verify that your submission was received. If it does not show you your latest submission, then we don't have it.
Should handin be broken at the deadline, email us ASAP and stop
editing stuff in your lab directory (or email the files in lieu of
You should also add a rule into your OCMail so that mail from the grader doesn't go into your Spam folder. (This seems to happen randomly throughout the semester.)
Look through your source files and be sure you've included you name at the top of all of them. If there are any known problems or incomplete features, document that also at the top of the file. If you adhered to the honor code in this assignment, add the following statement as a comment at the top of your main java file.
I have adhered to the Honor Code in this assignment.
You now just need to electronically handin all your files. Quit Eclipse and delete the class files. (Otherwise those will be handed in as well!)
% cd # changes to your home directory % cd cs151 # goes to your cs151 folder % handin # starts the handin program # class is 151 # assignment is 0 # file/directory is lab0 % lshand # should show that you've handed in something
You can also specify the options to handin from the command line
% cd ~/cs151 # goes to your cs151 folder % handin -c 151 -a 0 lab0
That's it! You've completed your zeroeth lab. Be sure to logout when you are done (icon is to the left of the terminal and globe icons).
Be sure that you have