The Practice and Philosophy of Object-Oriented Programming in Java
Return to Companion Site

How to Set Up IntelliJ IDEA for Java and JavaFX Development


You will need the following packages:

  1. The Java Development Kit. There are two major implementations: Oracle JDK and OpenJDK. The differ in terms of licensing and release schedules, but for personal use it really does not matter which implementation you choose. Just pick one and download/install the latest version (or see the note below about using an older version).
  2. IntelliJ IDEA (Community Edition). See the installation guide for OS-specific instructions if needed.
  3. Download JavaFX. This is a zipped folder named javafx-sdk (with version number appended). Unzip the folder and move it to a permanent location on your hard drive.

When you install the JDK, you will be prompted to create the home directory in a default location on your hard drive or to select another location — either way, make note of the location so that you can refer to it later. The following image shows the Windows installer saving the JDK to C:\Program Files\Java\jdk-14.0.1\.

Using an Older Version of the JDK

Java 8, released in 2014, includes all of the language and library features used in this book, so it is not technically necessary to have the most recent release. However, Oracle recommends uninstalling any versions prior to Java 11 for security reasons, noting also that the latest version will offer the newest feature updates, bug fixes, and performance improvements. If you do choose to use Java 8, you do not need to download JavaFX and you can skip the remaining steps below since JavaFX was part of the JDK 8. With the advent of Java 11 in 2018, however, JavaFX was removed from the JDK so that it could evolve at its own pace as an independent open-source project guided by Oracle and others in the OpenJFX community.

Step 2: Configuring IntelliJ IDEA for Java Development

After installing IntelliJ IDEA, you will need to configure it for Java development by specifying the location of the JDK home directory. To do this, start the IDE, click on the configure gear at the bottom of the welcome screen, and select Structure for New Projects:

The following dialog will appear:

Click the + icon to add a new JDK:

Enter or select the JDK home directory. In the example shown below, there are two versions available (13 and 14.0.1) and the latter is selected:

After selecting the JDK home directory, a list of class paths will automatically appear in the classpath tab:

Click the OK button. Your IDE is now configured with the JDK. However, for projects using JavaFX classes it will be necessary to perform one additional step.

Step 3: Adding JavaFX Libraries to your IntelliJ Project

If you create a new JavaFX application or open an existing one, you will notice compile-time errors in the editor: names of classes in the JavaFX API are not recognized. To fix this, you need to add the JavaFX libraries to the project. First, click on the File menu and select Project Structure. In the dialog that appears, select the Libraries tab and click the + icon to add a new Java library:

Find your javafx-sdk folder and select the lib subfolder:

Click the OK button to complete the process.

For troubleshooting information, consult the JetBrains help page.