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.

Any IDE can be used, however, the course staff is most familiar with VSCode and may not be able to help you with IDE issue if you choose to use a different IDE 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 Wednesday, April 3rd.

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 - SPR24), or stop by instructor/TA office hours.

What if you 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 your cs12sp24 account.

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 you system by going into the Extensions Tab in VSCode.

Getting the Code

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

  1. Download as a ZIP folder

After going to the Github repository, you should see a green button that says Code. Click on that button. Then click on Download ZIP. This should download all the files as a ZIP folder. You can then unzip/extract the zip bundle and move it to wherever you would like to work.

  1. Using git clone (requires terminal/command line)

    After going to the Github repository, you should see a green button that says Code. Click on that button. You should see something that says Clone with HTTPS. Copy the link that is in that section. In terminal/command line, navigate to whatever folder/directory you would like to work. Type the command git clone _ where the _ is replaced with the link you copied. This should clone the repository on your computer and you can then edit the files on whatever IDE you see fit.

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 Code 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 or pa0-starter-master (depending on how you have downloaded the code, but make sure that the folder you are using should be just 1 level above the src folder), and open it. This is how your directory structure should look like:

File Structure

There are a few options to run the file.

To compile and execute, type the following commands in the terminal. Make sure you run these commands from the src directory

Note: We are using main/ before because the file is inside the main folder in the src directory

Terminal Output

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

As we aren’t using Maven or Gradle, any instructions pertaining to them 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, which is 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