Java

From ScientificComputing
Jump to: navigation, search

Definition

Java is a high-level, general-purpose, memory-safe, object-oriented programming language. It is intended to let programmers write once, run anywhere.

Java on Euler

On Euler the following versions of Java are available:

Java version Module command
11.0.20.1 module load stack/2024-06 openjdk/11.0.20.1_1
17.0.8.1 module load stack/2024-06 openjdk/17.0.8.1_1
21.0.3 module load stack/2024-06 openjdk/21.0.3_9
8u141-b15 module load stack/2024-06 jdk/8u141-b15

Example Program

Create a file hello.java, with the content

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

Bring java and javac (the java compiler) to the command line with

module load stack/2024-06 openjdk/21.0.3_9

Compile the program hello.java

javac hello.java

which produces a file Hello.class. Then run the program with

java Hello

and the program should print

Hello, World!

to your terminal.