Setting Up Your Personal Development Environment

CS350, Summer 2024

Contents:

1 Overview

  1. Get (re?)-acquainted with the Eclipse and/or VSCode IDE.
  2. Prepare your personal development environment for the course.

2 Choosing your Development Mode

You are going to be doing a lot of Java programming in this course.

Now is the time, before you actually get involved with the details of an assignment, to decide how you are going to do that and to get everything set up that you need.

2.1 What You Need

You will need an environment that includes

There are two IDEs that I can recommend: Eclipse and VSCode. Both are quite usable for this course.

If you are unfamiliar with either Eclipse or VSCode, or with the Remote Display and Remote development modes, go back to CS252 and review section 4.3 Integrated Development Environments (IDEs).

If you are unfamiliar with git, go back to CS252 and review section 4.2 Version Control (git & GitHub).

In practice, the choice between Eclipse and VSCode will depend at least partly on where you want to work.

2.2 Where Do You Want to Work?

There are three major styles of development environment to consider.

2.2.1 Local Development

Having the IDE and all of the development environment components on your own PC is called local development.

Advantages:

Disadvantages:

2.2.2 Remote Display

In remote display development, we run the IDE, compiler, & debugger on a remote machine (e.g. the CS Linux servers) and have the results displayed on our local PC’s screen via X2Go.

Advantages:

Disadvantages:

This mode of development was a major theme of CS252, so you should already be prepared to work this way.

2.2.3 Remote Development

Remote development strikes a middle point between the extremes of running everything on your PC or running everything on the remote machine.

The compiler and debugger are run on the remote machine and do not need to be installed on your own PC.

The IDE, however, is installed and run on your own PC. It communicates with the remote machine via a combination of SSH and SFTP to show you your files on the remote machine, let you edit them, and to issue commands to the compiler and debugger on the remote machine.

Advantages:

Disadvantages:

3 Set Up Your Environment

3.1 If you want to do local development…

  1. Install the Java Development Kit (JDK) on your own PC.

    I strongly recommend that you stick with an LTS (Long Term Support) version of Java. Currently, the most recent LTS release is Java 21.

    • Get it here. Choose the appropriate “installer” package for your PC.
  2. Install your choice of Eclipse or VSCode on your PC.

  3. Install git on your PC.

    You have a choice of a “general” command-line git that can work with repositories hosted anywhere or an application specifically designed to work with repositories hosted on GitHub.

    • Windows users
      • I find the popular “Git bash” command-line tool to be unreliable with the current Windows OpenSSH (as of May 2024).
      • If you run either of the Unix emulators CygWin or WSL, you can install git there by following these instructions (CS252).
      • If you don’t want to run a Unix emulator, I recommend using the GitHub Desktop application.
    • MacOS Users.

3.2 If you want to do remote display…

3.3 If you want to do remote development…

You will use the Java compiler & tools and git on the CS Linux server.

You may have already done the steps below in CS252.

  1. Install VSCode on your PC following these directions.
    • In addition to installing the Java Extension Pack, you will also need to install the Remote - SSH extension.
  2. Configure VSCode to use SSH connections to the CS Linux servers to edit, compile, and run your programs.

4 Practice Using Your IDE

4.1 VSCode

If you are doing remote development, review how to connect remotely with VSCode, section 2.2.1, from CS252.

Whether you are doing local or remote development, try working through this Java in VSCode tutorial, starting at “Getting Started”, skipping over the installation instructions and picking up at “Creating a source code file”., then proceeding through “Navigate and Edit”, then “Project Management”, then “Run and Debug”.

Now try the following:

  1. In your operating system, create a directory to hold a Java project.

  2. Run VSCode. From the File menu, select “Open Folder” and navigate to the directory that you just created.

  3. From the File menu, select “New File…”, and create a new file named Hello.java.

  4. Your new Hello.java file should be open in the editor. In the body of the function, enter the code:

    public class Hello {
        public static void main(String[] args) {
            System.out.println("CLI Argument was " + args[0]);
        }
    }
    

    Save the file.

  5. In the right column, right-click on Hello.java and select “Run Java”.

    The program will run, but will complain about an out of bounds error.

    That’s because the program tries to print the first command line parameter (in the array args) and we did not supply any.

  6. From the “Run” menu, “Add Configuration”. A launch.json file will open up. It will contain two run configuration, one to launch your “current file” (whichever Java file you have open in the editor), and one to launch the “Hello” program.

    Delete the “Current File” configuration (everything between the { } and the following comma). You should be left with something like this:

    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Hello",
            "request": "launch",
            "mainClass": "Hello",
            "projectName": "hello_6684ef8f"
        }
    ]
    }
    
  7. Under the mainClass line, put

    "args": ["Hello world"],
    

    (If we needed more than one command line argument, we could add them within the [ ] as a comma-separated list.)

    From the Run menu, select “Run without debugging”.

    This time, the program should run correctly.

  8. In Hello.java, Set a breakpoint at the “println” line by clicking to the left of the line number so that a small red circle appears.

  9. From the Run menu, select “Start Debugging” (or just hit the F5 key).

    The program will start executing, but will pause at the breakpoint.

  10. Click the debug symbol on the left to open the debugging console. In the left column you will see the list of visible variables. Expand args to view its values.

  11. A toolbar has also appeared across the top center of the window. Hover your mouse over the various buttons in the toolbar to find the options for resuming execution and for stepping through the code. Use these to move forward through the rest of the function.

4.2 Eclipse

  1. From the File menu, create a new Java project in a directory of your choice.

    (Clear the “Use default location” checkbox and use the “Browse…” button to select a directory outside of your Eclipse workspace directory.)

  2. From the File menu, select “New”, then “Class”. Name your class “Hello”, check the box to create “public static void main”, then click “Finish”.

  3. Your new Hello.java file should be open in the editor. In the body of the function, put the statement:

    System.out.println("CLI Argument was " + args[0]);
    

    Save the file.

  4. In the right column, right-click on Hello.java and select “Run As”, “Java Application”.

    The program will run, but will complain about an out of bounds error.

    That’s because the program tries to print the first command line parameter (in the array args) and we did not supply any.

  5. In the right column, right-click on Hello.java and select “Run As”, then “Run Configurations…”.

    You might see a configuration already set up and named “Hello”. If not, select “Java Application” and then click the “New launch configuration” icon.

  6. In the Arguments tab, under “Program arguments:”, type “Hello world”, then click the “Run” button. This time, the program should run correctly.

  7. Set a breakpoint at the “println” line by double-clicking just to the left of the line number. A small blue circle should appear to mark the breakpoint.

  8. In the right column, right-click on Hello.java and select “Debug As”, then “Debug Configurations…”.

    Select the “Hello” configuration and click the “debug” button.

    The program will start executing, but will pause at the breakpoint.

  9. In the right column you will see the list of visible variables. Expand args to view its values.

  10. Hover your mouse over the various buttons in the toolbar to find the options for resuming execution and for stepping through the code. Use these to move forward through the rest of the function.