Setting Up Your Personal Development Environment
CS350, Summer 2024
1 Overview
- Get (re?)-acquainted with the Eclipse and/or VSCode IDE.
- 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
- a Java compiler, with debugger & associated tools,
- The
git
version control system, - an IDE that can aid in Java development and that
- support for working with version control systems such as
git
. - support for building with
gradle
- support for working with version control systems such as
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:
- If you have a good PC, this is fast and responsive.
- You don’t need a good Internet connection. You may not need to be on-line at all.
Disadvantages:
- If your PC is slow, your tools will be sluggish.
- There’s lots of software to install on your PC, and that take up space on your hard drive.
- If your operating system is different than the one used by the instructor, your compiled code may behave differently for you than it does for your instructor.
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:
- If you have a good Internet connection, this is fast and responsive (usually even if your PC is slow).
- You don’t need to install much on your PC – X2Go will do (and you should already have that from CS252).
- By running on the same CS machines that your instructor is likely to use, you avoid problems of compatibility when your code is graded.
Disadvantages:
- If your Internet connection is slow, everything will feel sluggish and unresponsive.
- If your Internet connection is down, you can’t work at all.
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:
- If your PC is slow, this will still feel reasonably fast and responsive, because most of the CPU-intensive tasks are done remotely.
- If your Internet connection is slow, this will still feel reasonably fast and responsive, because the amount of information being transferred is relatively small.
- There’s less software to install on your own PC than in local development.
Disadvantages:
- If your Internet connection is down, you can’t work at all.
- There are extra steps involved in starting each work session and in the initial setup of your project.
3 Set Up Your Environment
3.1 If you want to do local development…
-
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.
-
Install your choice of Eclipse or VSCode on your PC.
- If you want Eclipse, follow these directions.
- If you want VSCode, follow these directions.
-
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.
- Install a command-line
git
by following these instructions. - Alternatively, you can use the GitHub Desktop application.
- Install a command-line
- Windows users
3.2 If you want to do remote display…
-
Run X2Go on your own PC.
(Presumably, you have this in place from CS252.)
-
Run the Java compiler, Eclipse IDE, &
git
on the CS Linux servers.
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.
- Install VSCode on your PC following these directions.
- In addition to installing the
Java Extension Pack
, you will also need to install theRemote - SSH
extension.
- In addition to installing the
- 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:
-
In your operating system, create a directory to hold a Java project.
-
Run VSCode. From the File menu, select “Open Folder” and navigate to the directory that you just created.
-
From the File menu, select “New File…”, and create a new file named
Hello.java
. -
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.
-
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. -
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" } ] }
-
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.
-
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. -
From the
Run
menu, select “Start Debugging” (or just hit the F5 key).The program will start executing, but will pause at the breakpoint.
-
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. -
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
-
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.)
-
From the File menu, select “New”, then “Class”. Name your class “Hello”, check the box to create “public static void main”, then click “Finish”.
-
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.
-
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. -
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.
-
In the
Arguments
tab, under “Program arguments:”, type “Hello world”, then click the “Run” button. This time, the program should run correctly. -
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.
-
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.
-
In the right column you will see the list of visible variables. Expand
args
to view its values. -
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.