While I know that NB 12.5 does not officially support Java 17 I was curious
what would happen if I used JDK 17. I had already determined that NB 2.5 cannot
compile under JDK 17 because the JavaScript support is not available.
To run my tests I first used NB 12.4. With this version configured to use Java
11 to run NB I then created a simple Hello World and tested how it behaved if I
used Java 11, 16, Java 17 when I ran the code. I also compiled NB 12.5 using
JDK 11 on my Windows PC and ran the same two programs as I did on 12.4.
Side Note: The last time I compiled NetBeans, I think it was version 11.0, it
took 33 minutes. My new i9 based system now does it in 11 minutes.
Here is the console program:
package com.kenfogel.consoletest;
public class HelloWorld {
public void perform() {
System.out.println("Hello World " + System.getProperty("java.version"));
// Feature only available in 16 or 17.
// int x = 2;
//
// switch(x) {
// case 1 -> System.out.println("1");
// case 2 -> System.out.println("2");
// case 3 -> System.out.println("3");
// default -> System.out.println("default");
// }
}
public static void main(String... args) {
new HelloWorld().perform();
}
}
It is a Maven based project. The results were that my simple HelloWorld ran
under all three versions of the JDK. I did not install nb-javac.
Next, I tried a simple JavaFX program using JDK 17 and JavaFX 17-ea+14. It ran
flawlessly, still not using nb-javac. Here is that program:
package com.kenfogel.javafx_01_basicexample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Basic JavaFX program created all in code
*
* @author Ken
*/
public class MainApp extends Application {
private final static Logger LOG = LoggerFactory.getLogger(MainApp.class);
/**
* Start the JavaFX application
*
* @param primaryStage
*/
@Override
public void start(Stage primaryStage) {
// Set window's title
primaryStage.setTitle("Hello World!");
// Create a button
Button btn = new Button();
btn.setText("Say 'Hello World' " + System.getProperty("java.version"));
btn.setOnAction(event -> System.out.println("Hello World! " +
System.getProperty("java.version")));
// Control added to StackPane is centered in the pane
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
// Event when the window is closed by an external event such as by
// clicking on Window exit decoration (the X in the title bar).
// A Platform.exit() is implied but other tasks to carry out on exit
// can be called here
primaryStage.setOnCloseRequest(event -> {
LOG.info("Window close icon pressed");
});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
I am focused on Java 17 because upon its release developers will want to kick
the tires on it. Considering that NB is compiled on JDK 11, I wanted to know
what happens if a developer wanted to use JDK 17. I have many more programs to
try out, but my hope is that the amazing work all the committers have put in to
NB will allow users come next September to start playing with 17 without NB
getting in the way.
I have questions about compiling NB 12.5 with Java 11 and I'll ask them in my
next email.
Ken Fogel