Installing Java and JavaFX

rev. 22 July 2022

Installing the Java JDK

Install this if you are not doing JavaFX Programming Go to the adoptium.net and do the following. The site automatically detects your OS and offers the correct version.

  1. Download the Latest LTS release.
  2. Run the installer. Then do this in a command window in MacOSX or Windoze..
    $javac  -version
    javac 17.0.1
        
    This tells you that java17 is running on this machine. If you run linux, use --version to see the version.

Create this file using your text editor.


public class TestJava
{
    public static void main(String[] args)
    {
        System.out.println("Passed!");
    }
}

Navigate your cmd or terminal to the folder containing this file. Then (the $ below is your system prompt), type

$ javac TestJava.java

to compile and

$ java TestJava
Passed!

to run. You are ready to run and compile Java.

Installing the JavaFX JDK

Do this to program in JavaFX This JDK contains both a core Java JDK and the JavaFX JDK. It eliminates the annoyance of dealing with classpaths and it allows you to run and compile JavaFX programs using javac and java.

  1. Go to The BellSoft Site.
  2. Click on Download Current or LTS Release.
  3. Scroll down the page to find your OS.

    picture of BellSoft Site

  4. Select your chip.
  5. Pull down the menu next to the Package label and select FULL JDK.

Restart your command window session if you have one open.

Testing your JavaFX Install

Make this file in a text editor.


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.scene.control.Button;

public class HelloFX extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Button b = new Button("Quit");
        Label l = new Label("Hello, JavaFX " + javafxVersion 
            + ", running on Java " + javaVersion + ".");
        BorderPane bp = new BorderPane();
        bp.setCenter(l);
        bp.setTop(b);
        b.setOnAction(e -> System.exit(0));
        Scene scene = new Scene(bp, 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

Now compile and run using the command line. This window should pop up on your screen.

JavaFX Graphics window

Click on the quit button to dismiss it.

Where is the API Guide Bookmark this!

A Running Start Download s13.pdf for a quick introduction to JavaFX.