CS 240 Setup
Installing Java and an IDE
Java 21 is the officially supported version of Java for this course. If you haven't already installed it, you can download the JDK from the Temurin download site.
There is no required development environment for your work outside of class. The sections below includes instructions for configuring VSCode, Eclipse, or IntelliJ IDEA to support the course style requirements.
In-class coding evaluations will be configured for VS Code, so you should be comfortable with its use.
Select the IDE you wish to use:
- VS Code (REQUIRED FOR IN-CLASS CODING EVALUTIONS)
- Eclipse
- IntelliJ IDEA
- Other
VS Code
Download and Install
Download and install the latest version of Visual Studio Code. (Update the program if you already have it installed.)
Next, follow the instructions below closely to configure VS Code for this course.
Configuring VS Code
Install the following extensions:
Uninstall or disable the following extensions. These are installed by default with the Java Extension Pack, but we won't need them.
Setup Folder
Download and extract cs240_fa25.zip. It should contain:
.vscode
- settings and configuration files for CS 240bin
- binary files, which will be created automaticallylib
- required libraries, such as JUnitsrc
- source files, where all your programs will go
Make sure the resulting folder is stored in a sensible location on your computer: don't just leave it in your Downloads folder.
Now open the cs240_fa25
folder in VS Code. It should look like the image below:
Common Mistake
Make sure you open the cs240_sp25
folder, not the src
folder, or an enclosing folder.
Open src/demo/HelloWorld.java
, and press F5 to run the program (or click the little run triangle). VS Code will open a Terminal window. The terminal shows: (1) the command used to run the program, and (2) the program's output.
Packages
The demo
subfolder matches the package declaration in the HelloWorld.java
file (package demo;
). This is how Java organizes code into packages. You will need to make sure your subfolders match your package declarations.
For instance, if you have a file with package labs.dance;
, you should create a labs
folder inside src
, and a dance
folder inside labs
.
Enable Tests
In the sidebar, open the "Testing" pane (the icon looks like a beaker). Click on "Enable Java Tests", then select "JUnit Jupiter" in the command palette at the top.
You can now run tests from the Testing pane or in a file by clicking on the "Run Test" button next to a test method.
Run the tests in src/demo/HelloWorldTest.java
to verify that everything is working.
Eclipse
Download and Install
Download and install the latest version of Eclipse if you don't already have it. (Use the Eclipse installer and install the Eclipse IDE for Java Developers.)
Create a Workspace
When you first open Eclipse, it will ask you to select a workspace. This is the folder where Eclipse will store all of your projects. You should create a new folder for this course.
If you want to change the workspace later, you can do so by selecting "File->Switch Workspace".
Install Checkstyle Plugin
The Eclipse Checkstyle plugin can be installed by following the instructions on this page:
https://checkstyle.org/eclipse-cs/#!/install
Once the plugin is installed, the Google style configuration can be selected by accessing "Window->Preferences->Checkstyle" and selecting "Google Checks".
Configure Formatter
The Eclipse auto formatter can be configured to follow the Google guidelines by downloading the the following file:
- eclipse-java-google-style.xml (right-click and save as)
Then, in Eclipse, go to "Window->Preferences->Java->Code Style->Formatter" and click "Import" to import the XML file.
Setup Example Project
You will need to create a new Java project in Eclipse for each lab or assignment.
Let's create a simple project to get started:
- Select "File->New->Java Project".
- Name the project something like "demo".
- Make sure "Create separate folders for sources and class files" is checked.
- Make sure "Create module-info.java file" is unchecked.
- Click "Finish".
Your code will go in the src
folder of your project.
Download HelloWorld.java and HelloWorldTest.java and put them in the src/demo
folder of your project.
Packages
The demo
subfolder matches the package declaration in the HelloWorld.java
file (package demo;
). This is how Java organizes code into packages. You will need to make sure your subfolders match your package declarations.
For instance, if you have a file with package labs.dance;
, you should create a labs
folder inside src
, and a dance
folder inside labs
.
Setup JUnit
Open the HelloWorldTest.java
file. You should see a red underline under import static org.junit...
. Click on the red lightbulb and select "Fix project setup". Follow the prompts to add the JUnit library to your project.
Now you can run the tests in HelloWorldTest.java
by right-clicking on the file and selecting "Run As->JUnit Test". Or open the file and use the drop-down next to the run button in the toolbar.
Run the tests in HelloWorldTest.java
to verify that everything is working.
IntelliJ IDEA
Download and Install
Download and install the latest version of Intellij IDEA if you don't already have it.
Setup Example Project
You will need to create a new Java project in IDEA for each lab or assignment.
Let's create a simple project to get started:
- Select "File->New->Project".
- Choose "Java" from the list on the left.
- Name the project something like "demo".
- Make sure "Add sample code" is unchecked.
- Click "Create".
Your code will go in the src
folder of your project.
Download HelloWorld.java and HelloWorldTest.java and put them in the src/demo
folder of your project.
Packages
The demo
subfolder matches the package declaration in the HelloWorld.java
file (package demo;
). This is how Java organizes code into packages. You will need to make sure your subfolders match your package declarations.
For instance, if you have a file with package labs.dance;
, you should create a labs
folder inside src
, and a dance
folder inside labs
.
Install Checkstyle Plugin
You will need to install the Checkstyle plugin for IDEA. Follow these steps:
- Open Settings.
- Find the Plugins panel.
- Search for and install Checkstyle-IDEA (search in the Marketplace).
If prompted, restart IDEA. Once installed, you will find the Checkstyle panel in the sidebar.
- Once installed, find the Checkstyle panel in the sidebar.
- Select "Google Checks".
Setup Formatter
The IDEA formatting preferences can be configured to follow the Google guidelines by downloading the following file:
- intellij-java-google-style.xml (right-click and save as)
Then, in IDEA, go to "File->Settings->Editor->Code Style->Java" and import the XML file by clicking the gear icon and selecting "Import Scheme":
Setup JUnit
Open the HelloWorldTest.java
file. You should see an error on import static org.junit...
. Select the line and click on the red lightbulb. Choose "Add JUnit5 to classpath" or similar.
Follow the prompts to add the JUnit library to your project. You can now run tests from the "Structure" panel or by clicking the run button next to a test method.
Run the tests in HelloWorldTest.java
to verify that everything is working.
Other
If you have a different IDE that you prefer to use, go for it!
You're on your own for this one, but you can always find resources online.
I recommend configuring it to follow the Google style guide (or follow it yourself). You can find the style guide here.