JavaFX

JavaFX is now included in the Java Runtime Environment, superseding Swing as the recommended user interface toolkit for creating desktop applications.

The following lambda expression generates prime numbers below 100
import java.time.Instant;
import java.util.stream.IntStream;
public class Maths {
    public static void main(String[] args) {
        String primes = 
        IntStream.range(2, 100). //generate a sequence from 2 to 100
        parallel(). //returns a parallel stream, enabling concurrent execution
        filter(p->!IntStream.range(2, p).anyMatch(n -> p % n ==0)). //predicate determines if p is a prime number 
        mapToObj(p -> p+", "). //transform each int in the stream into a String followed by a comma
        collect(StringBuilder::new, StringBuilder::append, StringBuilder::append). //reduce stream to a StringBuilder
        toString(); //convert StringBuilder to String
		 
        System.out.println(primes);
    }
}
Using the above lambda expression, the following JavaFX application displays prime numbers in a graphical user interface
import java.util.stream.IntStream;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

//JavaFX applications extend Application. This class sets control layout programmatically; an alternative is to describe the layout with FXML markup 
public class Main extends Application {
    public static void main(String[] args) {
        Application.launch();
    }

    // The JavaFX runtime calls start(), passing in the primary Stage. A Stage is the top level JavaFX container.
    @Override
    public void start(Stage primaryStage) {
        // Layout controls programmatically using a BorderPane
        BorderPane pane = new BorderPane();

        // build four controls
        Label label1 = new Label("Limit");
        TextField limit = new TextField("1000");
        Button startButton = new Button("Start");
        TextArea textArea = new TextArea();
        textArea.setWrapText(true);

        // Add three controls to an HBox, then add the HBox to the top of the BorderPane
        HBox hbox = new HBox(10);
        hbox.getChildren().addAll(label1, limit, startButton);
        pane.setTop(hbox);

        		
        pane.setCenter(textArea); // add the TextArea to the centre of the BorderPane	
			
        Scene scene = new Scene(pane, 600, 400); // The Scene class is the container for all content.
        primaryStage.setScene(scene); // a Scene resides in a Stage
        primaryStage.setTitle("Prime numbers");
        primaryStage.show();

        //The button's setOnAction method takes an EventHandler argument. This can be written as a lambda expression
        startButton.setOnAction(event -> {
            int max = limit.getText().matches("\\d+") ? Integer.parseInt(limit.getText()) : 0; //check if TextField contains an int
            String primes = 
            IntStream.range(2, max). //generate a sequence from 2 to max
            parallel(). //returns a parallel stream, enabling concurrent execution
            filter(p->!IntStream.range(2, p).anyMatch(n -> p % n ==0)). //predicate determines if p is a prime number 
            mapToObj(p -> p+", "). //transform each int in the stream into a String followed by a comma
            collect(StringBuilder::new, StringBuilder::append, StringBuilder::append). //reduce stream to a StringBuilder
            toString(); //convert StringBuilder to String
			 
            textArea.setText(primes);
        });
    }
}