Setting Up Your Personal Development Environment
CS350, Spring 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, though you can wait to install that for a while. - 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
git
andgradle
yet (though, as of Summer 2021,git
is introduced in CS252). But those topics will come later. - support for working with version control systems such as
There are two IDEs that I can recommend: Eclipse and VSCode. Both are usable. Eclipse provides a more mature level of support for Java. It also includes an internal implementation of git
.
If you are unfamiliar with either Eclipse or VSCode, or with the Remote Display and Remote development modes, go back to CS252 and review sections: 4.4 Integrated Development Environments (IDEs), and 4.5 Debugging.
In practice, the choice 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.
2.3 Recommendations
2.3.1 If you want to do local development…
- Install the Java compiler & tools on your own PC.
- Install your choice of Eclipse or VSCode on your PC.
- Instructions can be found here.
- Install
git
on your own PC (optional but recommended).
2.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.
2.3.3 If you want to do remote development…
- Use the Java compiler & tools and
git
on the CS Linux server. - Install VSCode on your PC.
-
Configure VSCode to use SSH connections to the CS Linux servers to edit, compile, and run your programs.
-
2.4 Once You’ve Made Your Choice
-
If you are doing local development, install the Java Development Kit (JDK).
You should select an LTS (Long-Term Support) version of the compiler. As of when I am writing this, the most recent LTS version is Java 21.
- For Windows, follow these instructions
- For MacOS, follow these instructions
- For Ubuntu and similar Linux distributions, do
sudo apt-get update sudo apt-get install default-jdk
-
If you are doing local development, and have opted for the Eclipse IDE, get it here.
-
If you are doing remote development, or local development opting for VSCode, install VSCode from here.
Run it, click on the button to enter the list of extensions.
- Install the
Java Extension Pack
. - If you are going to do remote development, install the
Remote - SSH
extension.
- Install the
-
If you are doing local development, install
git
on your own PC.
3 Practice Using Your IDE
3.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 contian two run configuraiton, one to lauch 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 womehting 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
mailClass
line, put"args": ["Hello world"],
(If we needed more than one command line argument, we could add them within the
[ ]
as a comma-spearated 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.
3.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.