Skip to main content.

Assign 0: Getting Started with Java

Objectives:

Due: Tuesday 11:59 p.m.

Set Up

Installing Java

If you're on the lab machines, you can skip this step.

We will be using the latest version of Java: 16. Specifically, I recommend that you get Liberica, a free, supported, 100% open-source OpenJDK. Make sure you get the JDK (which includes the JRE), not just the JRE.

On the command line, confirm that you're using Java 16 by running
java -version
javac -version
and seeing that the version is 16.

Cloning the Repository

In your terminal, go to the directory where you are keeping your repositories for CSCI209. Clone the repository for this assignment. Add your name to the README, specifying that you're the author/owner of the repository.

Part 0: Practice on a Given Program

Part 1: Your First Program

In your favorite text editor, create a Java class called Intro in a file named Intro.java. The Intro class's main method should print out--on separate lines--your name, your favorite color, and your favorite pop culture character. For example:

Sara Sprenkle
Favorite Color: Purple
Favorite Pop Culture Character: Tina Belcher

All the top-down design principles from CS111 and CS112 apply in every computer science course. Do not try to write the entire program in one attempt. Break the problem into manageable pieces. Branch/commit/merge at good checkpoints.

You should write only a little code at a time, then compile and execute it (see directions below) so that you find bugs quickly. You're getting used to the new Java syntax, so I'm sure you'll run into problems. If you run into problems, compare your code to the examples from class.

Make sure your program is well-documented, as discussed in class.

Compiling the Program

In a terminal, from the directory that contains Intro.java, compile your program using javac Intro.java

If there are errors, fix those errors and re-compile until it works.

Executing the Program

In a terminal, from the directory that contains Intro.java, execute your program using the command
java Intro

If the output is not what you expect, edit your program, recompile, and execute. Remembering to recompile before executing will be hard to get used to at first. Keep in mind some of the benefits of compiling: it catches syntax errors and can improve the efficiency of your executing program.

When you're sure your program is working correctly, execute your program using the command
java Intro > output, which writes the output from java Intro into the file output.

Add your source code and output to the repository.

If you are spending more than about 30 minutes on this program, something is wrong. Talk to me.

Part 2: Debugging A Program

Objective: The goal of this part of the assignment is to get you familiar with the required Java syntax, the compiler's error messages, and how to fix the errors so that the program compiles. Debugging is one of the most important skills you learn from programming, so it's good to practice, especially on a small program.

The given Assign0.java program contains at least 4 errors. Some are compiler errors that the compiler will catch. Others are logic errors that the compiler won't catch. The errors are common--you'll likely make these mistakes yourself at some point in time. You'll find those bugs faster in the future since you've practiced debugging them.

Comment out the original code and note the cause of the error. Then, correct the code. (It is not enough to say how you changed the code; you must explain the cause of the error.)

Aim for the fewest number of changes to get the code to work as expected. You could rewrite the code from scratch, but that's not the goal/point of the assignment.

Since you are inexperienced with Java, what are good ways to figure out the errors? You should have several different approaches to solving these problems (and that doesn't involve Web searches).

Rationale: I could do a diff between the original version of the code your version of the code to see what you changed. I want you to show that you know why the error occured.

Saving the Final Output

After you're sure the program works correctly, save the output in a file called debugged.out, similar to how you did in the last problem. Add the file to your repository.

Submission

Submit your assignment by pushing the code, README.md, and output files to GitHub. Note that the .class files should not be included in the repository. I set up the .gitignore file to prevent you from adding the .class file.

Cleaning up your code

Great! You got it working! Before you submit, review your code. Is your code written in an (relatively) understandable way? Any extra code that you no longer need? Do you have appropriate comments? Does the code's indentation look like the examples?

Checking your work

It is recommended that you [re?]clone your project in a new directory, and then make sure that you can compile and run your programs. (This is, afterall, exactly the process that I'll use.)

Grading (70 pts)

You will be evaluated based on