xms and xmx Java

svg viewer

What is xmx and xms?

xmx and xms are JVM, Java Virtual Machine, command-line options/flags that are used by programmers to manipulate the heap size used by JVM. This allows them to optimize the speed and memory of different java applications.

About xms

  • xms is used to specify the initial lower bound of java heap memory size.
  • Default xms size is 1/64th of the physical memory size.
  • Format for specifying xms:
java -xms{Numerical Size}{Unit}

where Unit is k/Kk/K for kilobytes, m/Mm/M for megabytes, and g/G for gigabytets.

  • The numerical size must be a whole number.
  • By default, the size is in bytes.
// FORMAT: java -xms{Numerical Size}{Unit}
java -xms1G
java -xms512m
// Omitting Unit will result in the size being interpreted as byte
java -xms1024

About xmx

  • xmx is used to specify the upper bound of java heap memory size.
  • Default xms size is 1/4th of the physical memory size.
  • Format for specifying xms:
java -xms{Numerical Size}{Unit}

where Unit is k/K for kilobytes, m/M for megabytes, and g/G for gigabytes.

  • The numerical size must be a whole number.
  • By default, the size is in bytes.
// FORMAT: java -xms{Numerical Size}{Unit}
java -xmx1G
java -xmx256k
// Omitting Unit will result in the size being interpreted as byte
java -xmx512

Pitfalls

  • If the programmer initializes a fairly large heap size, then the Garbage Collector will consume more time while clearing the memory, which will slow down the program.
  • If the programmer initializes a fairly small heap size, then it is possible to run out of memory. Insufficient memory will throw the following exception: java.lang.OutOfMemoryError: Java heap space.
Q

What will be the lower and upper bound of java heap memory size for this:

java -xms1024
java -xmx256G
A)

upper bound:1024 bits
lower bound:256 gigabytes

B)

upper bound:256 gigabytes
lower bound:1024 bits

C)

upper bound: 0.25 terabytes
lower bound:1024 bytes

D)

upper bound:1024 bytes
lower bound: 256 gigabytes

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved