LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

java

launches Java applications

TLDR

Run class file
$ java [ClassName]
copy
Run JAR file
$ java -jar [application.jar]
copy
Run with classpath
$ java -cp [path/to/classes] [ClassName]
copy
Set heap size
$ java -Xmx[512m] -jar [app.jar]
copy
Run with system property
$ java -D[property=value] [ClassName]
copy
Show version
$ java -version
copy
Run single source file
$ java [Source.java]
copy

SYNOPSIS

java [options] class [args...]java [options] -jar jarfile [args...]

DESCRIPTION

java launches Java applications by loading and executing compiled bytecode in the Java Virtual Machine (JVM). It supports class files, JAR archives, and since Java 11, single source-file programs.The JVM handles memory management (garbage collection), threading, and platform abstraction. Memory is configured via -Xms (initial heap), -Xmx (max heap), and -Xss (stack size). System properties (-D) configure application behavior at runtime.

PARAMETERS

CLASS

Main class to execute.
-jar FILE
Execute JAR file.
-cp PATH
Class path for dependencies.
-Xmx SIZE
Maximum heap size.
-Xms SIZE
Initial heap size.
-D PROP=VAL
Set system property.
-Xss SIZE
Thread stack size.
-ea, --enableassertions
Enable assertions.
--enable-preview
Enable preview language features.
-verbose :class|:gc|:jni
Enable verbose output.
-version
Show version information.
--help
Display help information.

CAVEATS

Requires JRE/JDK. Version compatibility matters. Memory settings may need tuning.

HISTORY

Java was created by James Gosling at Sun Microsystems in 1995. It's now maintained by Oracle and the OpenJDK community.

SEE ALSO

javac(1), jar(1), jps(1), jstack(1)

Copied to clipboard
Kai