CSE 12 Programming Assignment 0 (Optional)

Computer Setup

This optional assignment will teach you how to setup Java and VSCode, get the starter code from GitHub, and how to run VSCode projects from your own computer. If you already have the JDK installed from a previous quarter and a way to edit, compile and run Java programs, then you can skip this assignment. If you plan on using the lab computers in the CSE basement, you can also skip this assignment.

We recommend using an integrated development environment (IDE) such as VSCode for CSE 12. IDEs differ from text editors like Sublime in integrating code editing with building and testing capabilities. Although you are welcome to use any IDE or text editor for programming, the course staff is most familiar with VSCode and may not be able to help you with programming environment issues if you choose to use an environment such as IntelliJ or Eclipse.

There is no submission or grade for this assignment. You should complete the installation and setup of your Java tools prior to starting PA1 which will be released on Monday, July 1st.

If you run into any problems, please reach out to a tutor during tutor hours using https://autograder.ucsd.edu/ to get 1-on-1 help (make sure to select CSE12 - SS124), or stop by instructor/TA office hours.

What if I already have a different version of Java? In general, you will most likely be fine, but if you run into problems compiling and running your code, we will suggest uninstalling your old version and reinstalling the latest JDK.

Using the CSE Basement Lab Computers

Log into a lab machine using your regular UCSD credentials.

Download Java & VSCode

Step 1: Installing Java and VSCode

General instructions for setting up your environment and installing Java and VSCode can be found in this document.

Step 2: Installing Extension Pack for Java

The Extension Pack for Java adds support for Java and JUnit, and you need to install it on your system by going into the Extensions Tab in VSCode.

Getting the Code

The starter code can be found at the followingGithub repository. If you are not familiar with Github, here are two easy ways to get your code.

If you are unsure or have questions about how to get the starter code, feel free to make a Piazza post or ask a tutor for help.

Running a Java Program in VSCode

Open VScode and wait for it to prompt you to Open a Folder. A new window will open for you to select a folder to open. To open the given starter code, navigate to the folder pa0-starter (if you got the code using git clone) or pa0-starter-master (if you downloaded the code as a ZIP file), and open it. This is how your directory structure should look like:

File Structure

There are a few options to run the file.

First option: open the VSCode terminal, and use command line to compile and execute the Java file.

Running through Terminal

In the terminal, go to the src directory that is inside the pa0-starter or pa0-starter-master directory. To compile and execute the program, type the following commands in the terminal.

Note: We are using main/ before because the file is not in the src directory that our terminal is in, it is in the main directory that is inside the src directory.

Terminal Output

Second option: use the Play button on the top right of the window.

Running through Play Button

You should now see “Hello World!” printed to the VSCode terminal. You have successfully ran a program on VSCode!

Running Tests through JUnit

JUnit is by far the most popular and widely-used unit testing framework for Java. We will use the version 4 of this framework: JUnit 4. In JUnit, you build one or more test classes and use a test runner to execute them.

The Test Runner for Java extension can be used for running JUnit tests with VSCode. This extension comes in the Extension Pack for Java mentioned in Part 1, and does not need to be installed separately if the Java Extension Pack was installed: https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test

Documentation for using it can be found here: https://code.visualstudio.com/docs/java/java-testing#_enable-testing-and-adding-test-framework-jars-to-your-project

Any instructions pertaining to Maven or Gradle can be ignored. Follow instructions for using it with an “Unmanaged Folder”, and enable JUnit through the Testing Explorer.

Important note: When enabling tests through the extension, make sure to select JUnit as your test framework instead of JUnit Jupiter or TestNG. JUnit is JUnit 4 (the version we will be using in this course).

Setup tests with JUnit 4

If you follow the instructions and tests don’t run, run the following command in VSCode:

Clean Java Language Server

Reload and Delete

Run Tests in VSCode

Though we very strongly recommend using VSCode, if you are still interested in working on Eclipse, you can follow this documentation to install Eclipse, and this documentation to setup JUnit in Eclipse

Submitting

There is no submission for this assignment.

Java Refresher Resources

Text-Based