Practical Java Programming For IOT, AI, and BLOCKCHAIN – Part 1 – Set up

Practical java Programming For IOT, AI, AND BLOCKCHAIN, Dr. Perry Xiao, John Wiley & Sons, Inc., Copyright 2019, ISBN 978-1-119-56001-2. $40 US / $48 CA.

I just bought this book (28-Sep-2020). The content is more intriguing than the traditional approach to “programming for the sake of programming” and at first glance provides a sufficient level of teaching to make the book useable.

Getting Java

A pre-requisite to using Java is to install a version of it on your computer. Visit the Oracle Java SE Downloads page for more details to setup your machine https://www.oracle.com/java/technologies/javase-downloads.html. Follow the installation instructions for your operating system.

Note that you will have the option to click on the Next Steps button when the installation is complete. This takes you to the JDK Documentation page where you will find an overview and additional tools including JDK Tool Specifications, JShell Users Guide, Javadoc Guide, and the Packaging Tool User Guide.

Update the PATH variable so javac can be found to run your JAVA programs.

JavaFX is not included in the JDK and must be downloaded separately. More on this later.

Java Online

If you’re not prepared to download Java just yet, you can use one of several online compilers.

Java IDE

You have a variety of Integrated Development Environments (IDE’s) to choose from including NetBeans, Eclipse, and JetBrains IntelliJ IDEA which also happens to be our IDE of choice. Although we’re using IntelliJ Ultimate, the community edition offers features and capabilities to support the requirements of many Java programmers.

JavaFX and IntelliJ IDEA

As mentioned earlier, JavaFX is now managed by a third party (Gluon), however, it is readily available and interfaces nicely with IntelliJ. Refer to the article at https://www.jetbrains.com/help/idea/javafx.html#create-project for more details on getting and using JavaFX with IntelliJ IDEA.

We’re using JDK 15 and since JavaFX is not included as part of the JDK as of Java 11 and later, it’s important to follow the directions on the IntelliJ IDEA website (https://www.jetbrains.com/help/idea/javafx.html#run) to modify the Project Structure and add the VM options.

Project Structure

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S or click the Project Structure button on the toolbar.
  2. Open the Libraries section, click the New Project Library, and select Java.
  3. Specify the path to the lib folder in the JavaFX SDK package.

Add VM options´╗┐

  1. From the main menu, select Run | Edit Configurations.
  2. Select Application | Main from the list on the left.
  3. In the VM options field, specify: --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml and any other modules your application may require. Instead of %PATH_TO_FX%, specify the path to the JavaFX SDK lib directory. If you’re using JavaFX SDK 14 together with OpenJDK 14, add one more VM option: --add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED

To run the application, from the main menu, select Run > Run ‘Main’. The IDE compiles the code and the application window appears if the project is configured correctly and there are no errors in the code.

If you are running Java 15 SDK and the latest JavaFX SDK, the above will provide a working Java environment from within IntelliJ IDEA.

Set Up JavaFX and Scene Builder

The JavaFX plugin must be enabled to use JavaFX and Scene Builder with IntelliJ IDEA.

Scene Builder from Gluon is a free and open source drag and drop WYSIWYG rapid development application that works with the JavaFX ecosystem. Scene Builder is cross-platform with versions available for Windows, Linux, and Mac OSx.

Download Scene Builder from the Gluon Website and follow the installation instructions for your operating system. If you use the “advanced” options, you can choose where the JavaFX SDK is installed on your system and will make it easier to find it later.

File | Settings | Plugins and scroll down to the JVM Frameworks category and continue scrolling to find JavaFX bundled. Click the checkbox to enable JavaFX support as pictured below:

Now, Java FX will appear on the left sidebar when you want to create a New Project:

Leave a Reply