LinuxCommandLibrary

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. It loads and executes compiled bytecode in the Java Virtual Machine.
The runtime handles memory management, threading, and platform abstraction. It supports both class files and JAR archives.

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.
-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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard