Java Tools Tutorials - Herong's Tutorial Notes - Version 5.32, by Dr. Herong Yang
Option '-X' - Specifying Non-Standard Options
This section provides a tutorial example on how to use the '-X' option for the 'java' tool to specify non-standard options. The tutorial example shows how to control the memory size of the JVM.
"java" can also take "non-standard" options by using the "-X" option.
Two of the "non-standard" options are very useful to control the memory size of the JVM to be launched.
-Xmsn -Xmxn
where "ms" specifies the initial size of the JVM, "mx" specifies the maximum size of the JVM, and "n" specifies the memory size in bytes, kilo bytes or mega bytes. For example: -Xms32M and -Xmx64M.
Here is a program to show you how to use these options:
/* ShowMemory.java #- Copyright (c) 2015, HerongYang.com, All Rights Reserved. */ class ShowMemory { public static void main(String[] a) { Runtime rt = Runtime.getRuntime(); System.out.println(" Free memory: " + rt.freeMemory()); System.out.println("Total memory: " + rt.totalMemory()); while (true); } }
I launched the program with different options:
C:\herong>javac ShowMemory.java C:\herong>java ShowMemory Free memory: 15709392 Total memory: 16252928 C:\herong>java -Xms32M -Xmx128M ShowMemory Free memory: 31727064 Total memory: 32440320 C:\herong>java -Xms64M -Xmx128M ShowMemory Free memory: 63806136 Total memory: 64880640
Note that ShowMemory is running an infinite loop at the end. You need to stop the program by "Ctrl-C"
Last update: 2015.
Table of Contents
'javac' - The Java Program Compiler
►'java' - The Java Program Launcher
'java' - Java Launching Command and Options
Launching Hello.java - My First Java Program
Option "-classpath" - Specifying Class Path
Option '-jar' - Specifying Executable JAR Files
►Option '-X' - Specifying Non-Standard Options
'javaw' - Launching Java Programs without Console
'jconsole' - Java Monitoring and Management Console
'jstat' - JVM Statistics Monitoring Tool
jvisualvm (Java VisualVM) - JVM Visual Tool
'javap' - The Java Class File Disassembler
'keytool' - Public Key Certificate Tool