Assignment 0: Welcome to CSE131!
Pre-Lab 0 - CSE131 & Version Control
In CSE131 this semester, we will be using Git as our version control system.
Version control systems (VCS) are great for when you want to record who did what for which file or set of files, and it is especially useful when multiple people collaborate on projects, as you will be in this course.
Before working on any project, you must check out your repository. The instructions for this will be later on in this writeup.
The general workflow of Git, following the repository being checked out, is as follows. Don't worry if you don't understand some of the terms yet, they'll make sense as we go through this studio and the coming lab:
- Pull from the master/origin
- Do work on one/some of your files
- Commit and/or push your work back to the origin
- Repeat steps 1 through 3
These steps will have to be repeated and followed for every assignment you work on throughout the duration of this course.
Whenever you sit down to work on an assignment, you must always pull from origin/master before working. If you don't, it is possible that you'll cause a conflict.
Getting Started with Java in eclipse with Git
Professional software developers use an Integrated Development Environment (IDE) that includes a text editor (for creating source code), a compiler (for translating source code into executable code), and a debugger (for finding errors). In this course, we'll be using eclipse, a popular IDE that supports (among many other things) programming in Java.
Professional software developers also use a versioning repository to store their code, so that they can share their code easily and keep track of the changes they make. We will be using the git revision control system. It will allow you to submit your code for grading and to share it with TAs who can help you with problems you might encounter.
This part of the lab explains how to get started using eclipse with git.
- Start eclipse:
- Launch eclipse. You can use the default location for your workspace.
The first time eclipse starts, it may be slower than usual. You will be asked where you want your workspace to be.
After eclipse starts up, click the 'X' on the 'Welcome' tab at the top to close the welcome screen.
-
Identifying your repository:
Open the git tutorial in another window, and follow the steps given there to set up your git repository.
-
Look at your project: If you are back in the Java view, then you should see a project in the Package Explorer at the left side of the eclipse window.
-
Look at the source code:
-
In the Package Explorer, expand the project by clicking on the '+' sign or little triangle to the left of the project name. You will see that it contains an entry for labs, which is a folder that contains packages of code.
- Expand the labs folder (click on its '+' sign or triangle).
- Each lab you complete is given to you in a separate package. For this lab, expand the lab0 package.
- Double-click the file named RobotController.java to open it. Look at the source code in the middle window. You'll see instance variables, methods, and a main method.
For now, you don't need to understand what you see. We just want the computer to run this program.
-
-
Run the program: Right click on RobotController.java and select Run as -> Java application. In the bottom right corner, you will see a GO button.
Click the Go. The program should create a robot, and you should see the robot start to move. - Modifying programs: In general, before you can execute a Java program, it must first be compiled (translated) into byte code that can be executed by the Java interpreter. A program that performs this translation is called a compiler. Eclipse checks your files to see if they will compile, and it marks errors so you can correct them. If you position the mouse cursor over an error icon or a red underline, a description of the error will be displayed.
Try typing some random text into the RobotController.java file to introduce an error. You should see an error icon appear at the left. Note that sometimes the error message appears on the line after the error. At the bottom of the window, you'll see console and problems. The console window shows any printed output of the program. If you click on problems you'll see a list of the errors, and clicking on an item in the list will take you to the location of that error in the Java file so you can correct it. Undo your typing, or close (without saving) and re-open the file.
-
Make the robot do your bidding: So your real assignment here is to provide some instructions so that the robot draws a house.
-
Open up the RobotInstructions file, which is also in your lab0 package. This is where the commands to move the robot are written.
You now have two files open in eclipse:
- RobotController.java is the main file. You always run the application using the instructions given above for this file.
- RobotInstructions.java is the file that contains code directing the robot to move. This is the file you will modify to change the robot's behavior.
-
Modify some of the robot instructions, and re-run the program, to gain an understanding of how the instructions in this file affect the robot's behavior.
Really? We're asking you to program even though you probably don't much about Java yet?
Well, yes.
Even after you have learned much about Java, programming, and computer science, you may come across some code that you want to modify to change its behavior. This takes some courage, but see if you can figure out what the robot's instructions do, based on observing the robot and reading the code. Make some changes to the code to test your hypotheses. Soon you will have the robot doing your bidding.
-
Once you have the hang of it, try to have the robot draw a house.
Tip: Since RobotController.java was the program most recently run, you can run it again simply by clicking the green arrow on the toolbar at the top.
Each time it runs, you should see the results of your most recent modifications.
If you pause with the mouse over a location on the map, the x, y coordinate of your mouse location will be shown on the screen.
-
After 20 minutes of successful house building, don't spend much more time trying to get the robot to draw exactly the house you envision. Get comfortable with controlling it for a bit, and then you can stop worrying about the exact form your house will take.
-
-
Commit your work: Now that you have modified a file, take a look at the Package Explorer window and you should see some > signs next to the files that have been changed. The > sign warns you that you have modified files that have not been committed back to the repository. The files won't be visible by TAs or the instructor until you commit them.
To commit them, locate the name of your project (your name and ID) in the package explorer window of eclipse. Right (control) click on that, go down to Team… and select Commit. Enter a commit message, then click the Commit and Push button.
Tip: It is good practice to commit your code often. You can always recover any previously committed version of your software. Committing your code allows you to work on the code from a different computer, and ensures that you do not lose your work should your computer fail.
You now know the basic steps to create projects, as well as open, edit, compile, and run Java programs in eclipse. You should also have a basic understanding of sequential execution and how to call methods on objects. Please ask if you have questions about any of this.
Course Information
Take some time to peruse the web site. Are you clear about course policies concerning grading and attendance?
- How do studios count toward completion?
- How do labs count toward completion?
- What happens if you cannot turn in a lab on time?
Submitting your work
To submit your work, contact the instructor or a TA. They will walk you through the submission process. Be prepared to show them the work that you have done and answer their questions about it!