Tuesday | 21 MAY 2024
[ previous ]
[ next ]

Notes on Installing Java and JavaFX

Date: 2022-12-28

Some notes on setting up Java for my course.

Installing Java

First step is to get the JDK, the Java Development Kit.


Get the zip file and extract it to C:bin.

Now we need to add java to the environment so that windows knows about it.

This is a system variable.

JAVA_HOME =  C:\bin\jdk-19.0.1

You will also need to add the bin directory to the PATH so java can be used from the commandline.


Open the command prompt and simply type in java. This should result in the java help being printed.

Now we have Java ready to go.

Installing JavaFX

Next up, javafx, the GUI library.


Download the SDK, the software development kit as a zip. Extract the zip to C:bin as well.

Eclipse - The Editor

Download Eclipse as a zip package and we will do the same thing as before, extract it to C:bin.


We should now have the following structure in C:bin:


Hello World in Java

The first step is to make sure java is installed properly before we get to JavaFX.

To do this, make a hello-world project and quickly get something on the screen.

package helloworld;
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!"); 

Hello World with JavaFX

The first step to getting JavaFX working with eclipse is to follow the below instructions:


A hello world example


import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
    public static void main(String[] args) {
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
        StackPane root = new StackPane();
        primaryStage.setScene(new Scene(root, 300, 250));