Java

JAVA

OpenJDK is the open source implementation of java platform.

Compiler Version

To check the version of javac Compilers, type:

javac -version

output:

javac 1.8.0_275

Compiling a Code and Executing

Interactive

Request a compute node

srun --pty bash

Create a directory 'hello' in your home directory (example: /home/<caseID>/java/hello).

mkdir -p java/hello

Copy this file "Hello.java" in this directory

package hello;

public class Hello {

    public static void main(String[] args) {

        for (int i=0; i < args.length; i++) {

            System.out.println("Hello " + args[i]);

        }

    }

}

When at java directory (example: /home/<caseID>/java) , issue a compiler command:

javac hello/Hello.java

Now, you will see two files - Hello.java and Hello.class in hello directory.

Execute with a command:

java hello.Hello World!

You will see the output: Hello World!

Batch Job

Copy this job.slurm file in the java directory

#!/bin/bash

#SBATCH --time=00:01:00

#SBATCH --nodes=1

#SBATCH --cpus-per-task=1

#SBATCH -J java

#SBATCH -o java.o%j

cp -r hello $PFSDIR

cd $PFSDIR

java hello.Hello World

Submit the job

sbatch job.slurm

You will get the same output - Hello World in java.o<jobid> file.

JAVA Applet

Refer to JAVA Applet @HPC

References:

1. OpenJDK