Saturday, October 26, 2013

Check running Java and JavaFX version using Java code at run-time

To check the version of running Java and JavaFX in your Java code, you can get property of "java.version" and "javafx.runtime.version" by calling System.getProperty() method.

System.getProperty("java.version");
System.getProperty("javafx.runtime.version");

Example in Java Application:
Example in Java Application

package java_version;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class Java_version {

    public static void main(String[] args) {
        
        System.out.println("java.version: " + System.getProperty("java.version"));
        System.out.println("javafx.runtime.version: " + System.getProperty("javafx.runtime.version"));
    }
    
}


Example in JavaFX Application:
Example in JavaFX Application

package javafx_version;

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;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_version extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        System.out.println("java.version: " + System.getProperty("java.version"));
        System.out.println("javafx.runtime.version: " + System.getProperty("javafx.runtime.version"));
        
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            
            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

No comments:

Post a Comment