Due before 9:59:59pm, Tuesday Sep 05 2017
or ASAP for late enrolees, new to CS labs
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. You should be sure to do Part 5 on time (sending me an email), but 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 and didn't sign up on the list during the first day of class, see Chris Mohler in the OCTET office (King 125) 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. This 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 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.
You should just accept the default for workspace. (Usually ~/workspace/) Please do not select your csci151 folder as your default workspace. It'll take a bit 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. Good times.
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 it 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 things 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 change the preferences "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 box marked "Perform the selected actions on save". You can have 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 settings under "Java", "Code style", "Code Templates", "Comments", "Overriding methods" to match "methods". (Just copy and paste the Pattern window contents from "Methods" to "Overriding methods".)
In recent versions, Eclipse likes to put the *.class files in a different folder than your *.java files. However, this makes things a bit harder to go between eclipse and a normal editor. Change the preferences by selecting "Java" and "Build Path" and change the value of 'source and output folder' radio button to be "Project" instead of "Folder". Do not change the value of Source folder from src or Output folder from bin -- this is the radio button only. If you change only two settings, do this one too!
While you are working on stuff, you'll probably find that there are lots of 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.
As a reference guide for some such shortcuts and nifty things, I'll refer you back to the eclipse tutorial, and this list here:
Now we should create a project in our lab0 folder like 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. We won't be using them for this.
Now let's create a class that will tell the user a little bit about yourself.
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 there is both Hello151.java and Hello151.class 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've not actually tried to run your program, 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("When I graduate, I will donate 10% of my salary to the CS department.");
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".
If you want to try running your program from the command line then you should
Note that if that didn't work, and you see that you have bin and src folders in your 151/lab0 folder, you missed one of the important steps above.
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
Last semester this wasn't needed on lab machines, but was on your own laptops.
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 last semester. Run away from the fish!
I'll probably give you instructions on how to use handin as shown below as part of your instructions each week, but I suspect you've got the hang of it by now if this is your second CS class.
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 a submission).
We will be using iClickers to foster class discussion and the like. You need to go to the Blackboard page for this class and register your clicker. Do so, and bring it to class on Monday.
Now that you're familiar with the lab, I'd like you to share some info with me. When you send me an email, please include cs151 in the subject as that should bypass my spam filter and make it stand out in my inbox. Please send me an email with the following information:
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