← 返回命令列表

Linux command

java 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run class file

java [ClassName]

Run JAR file

java -jar [application.jar]

Run with classpath

java -cp [path/to/classes] [ClassName]

Set heap size

java -Xmx[512m] -jar [app.jar]

Run with system property

java -D[property=value] [ClassName]

Show version

java -version

Run single source file

java [Source.java]

说明

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.

参数

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

FAQ

What is the java command used for?

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.

How do I run a basic java example?

Run `java [ClassName]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -jar _FILE_ do in java?

Execute JAR file.