Code Samples

Code samples shown during lectures, and referenced in the slides, are located in this public Git repository.
To get a local copy, git clone https://git.uwaterloo.ca/cs349-public/1209.git.

You are allowed to use code from these samples in your assignments.

These videos walk through installing Git, Gradle, and Java and opening and building sample code with IntelliJ. You can also just skip to the Setup section below.

Setup

You require the following tools installed on your computer:

  1. Git Client. You will need this to get code samples and submit assignments.
  2. Gradle. This will be used to build your projects.
  3. Open JDK 11. The Java SDK that we will use.
  4. IntelliJ IDEA Community. This is a powerful Open Source Java IDE that you will need for some assignments.

Configuring IntelliJ

IntellIJ with its default configuration should work fine. Make sure you have the following plugins installed (under File -> Preferences -> Plugins).

Opening Existing Projects

To open an existing project, File -> Open and navigate to the top-level directory containing the build.gradle file. Do NOT open a specific file, just the directory. If done properly, IntelliJ will open the project (and you'll see Gradle messages as it loads the project).

All of the code samples in the public repository (above) were tested with IntelliJ 2020.1 and Gradle 4.5. They should all open using this method!

Creating a New Project

The following steps will setup a Gradle project that works from both the command-line and from within IntelliJ.

  1. In IntelliJ, File -> New Project. Select Gradle/Java as the type of project.
  2. Provide a name and location, and click OK. This will create a project.
  3. From the Project panel on the left (Cmd-1 to toggle it), you will see a list of files. Open "build.gradle".
  4. Add the following to the default build.gradle file:
      
      plugins {  
        id 'java'  
        id 'application'  
        id 'org.openjfx.javafxplugin' version '0.0.8'  
      }  
    
      application {
        mainClassName = 'Hello' // points to your class
      }
    
      javafx {
        version = "11.0.2"
        modules = ['javafx.controls', 'javafx.graphics']
      }
    
    
  5. Create a source file in the src/main/java folder (in this example, Hello.java containing class Hello).
  6. From the Gradle menu (View -> Tools -> Gradle), you should be able to Build and Run your application.

A working copy of this project can be found in the repository.