On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

Answer from stones333 on Stack Overflow
🌐
IBM
ibm.com › docs › en › was-nd › 8.5.5
Modifying the JVM heap size - IBM Documentation
February 9, 2026 - Typically, the total value of all server instance JVM heap sizes on a specific node must be less than half of the total RAM of that computer. The default maximum heap size value is 256 MB.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › gctuning › ergonomics.html
Ergonomics - Java
October 20, 2025 - The maximum pause-time goal is specified with the command-line option -XX:MaxGCPauseMillis=<nnn>. This is interpreted as a hint to the garbage collector that a pause-time of <nnn> milliseconds or fewer is desired. The garbage collector adjusts the Java heap size and other parameters related to garbage collection in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds. The default for the maximum pause-time goal varies by collector.
Top answer
1 of 10
669

On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

2 of 10
130

For Java SE 5: According to Garbage Collector Ergonomics [Oracle]:

initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

UPDATE:

As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

with the exception of 32 bit platforms running a version of the Windows operating system. On all other platforms the default values are the same as the default values for version 1.4.2.

In the J2SE platform version 1.4.2 by default the following selections were made

  • initial heap size of 4 Mbyte
  • maximum heap size of 64 Mbyte
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-is-the-default-max-java-heap-size-determined
How is the default max Java Heap size determined? - GeeksforGeeks
July 23, 2025 - The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one-fourth of the physical memory up to a physical memory size of 1 gigabyte.
🌐
Delcastanher
delcastanher.github.io › posts › java 17 heap space
Java 17 Heap Space | Delcastanher's Memory Allocation
July 11, 2023 - The heap is created when the Java Virtual Machine starts up and may increase or decrease in size while the application runs. 2 · These are heap size default selections: Initial heap size of 1/64 of physical memory; Maximum heap size of 1/4 of physical memory.
🌐
Baeldung
baeldung.com › home › spring › spring boot › what are the spring boot default memory settings?
What Are the Spring Boot Default Memory Settings? | Baeldung
January 8, 2024 - It’s the percentage of the total heap size that when reached causes sufficiently long-living objects to be promoted from the young generation to the old generation. Its default value is 25%. Since Java 8, we also have the meta-space as part ...
🌐
W3Docs
w3docs.com › java
How is the default max Java heap size determined?
For systems with 1 GB or more of physical memory, the default maximum heap size is set to 1/4 of the physical memory up to a maximum of 1 GB. For example, on a system with 4 GB of physical memory, the default maximum heap size would be calculated ...
🌐
Oracle
docs.oracle.com › en › graalvm › jdk › 17 › docs › reference-manual › native-image › optimizations-and-performance › MemoryManagement
Memory Management
April 21, 2026 - If the same image is executed on a machine that has 32GB of RAM, the maximum Java heap size will be set to 25.6GB. Note that this is just the maximum value. Depending on the application, the amount of actually used Java heap memory can be much lower. To override this default behavior, either ...
🌐
Baeldung
baeldung.com › home › java › jvm › jvm parameters initialrampercentage, minrampercentage, and maxrampercentage
JVM Parameters InitialRAMPercentage, MinRAMPercentage, and MaxRAMPercentage | Baeldung
June 5, 2024 - The MinRAMPercentage parameter, unlike its name, allows setting the maximum heap size for a JVM running with a small amount of memory (less than 200MB). First, we’ll explore the default value of the MinRAMPercentage: $ docker run openjdk:8 ...
Find elsewhere
🌐
Gigaspaces
docs.gigaspaces.com › 16.2 › production › production-jvm-tuning.html
JVM Settings and Tuning
The -XX:MaxDirectMemorySize option in Java 17 allows you to specify the maximum amount of memory that can be allocated for direct buffers used by the java.nio package, such as ByteBuffer.allocateDirect(). This memory is allocated outside of the Java heap, often by the operating system, and is not subject to garbage collection by the JVM. Direct memory is used for operations that require interaction with native code or I/O operations, such as reading or writing data from files, network sockets, or using certain APIs like NIO channels. By default, the maximum direct memory size is limited by the maximum heap size (-Xmx), but -XX:MaxDirectMemorySize allows you to specify a separate limit.
🌐
Eclipse OpenJ9 Blog
blog.openj9.org › 2020 › 04 › 30 › default-java-maximum-heap-size-is-changed-for-java-8
Default Java Maximum Heap Size is changed for Java 8 – Eclipse OpenJ9 Blog
April 30, 2020 - From OpenJ9 release 0.20, The default Java Maximum Heap Size (Xmx) is changed to be consistent with Java 11, so by default in Java 8, 25% physical memory up to 25GB for the Xmx will be expected.
🌐
Medium
medium.com › @marcoghisellini › spring-boot-default-memory-size-84b89ade7b10
Spring Boot — Default memory size | by Marco Ghisellini | Medium
April 18, 2025 - Jvm reserves half of physical memory for Max heap size and 1/64th of physically memory for Initial heap size. Unfortunately, this cannot be less than 8Mb, so, it sets this value as default.
🌐
Oracle
docs.oracle.com › cd › E92519_02 › pt856pbr3 › eng › pt › tsvt › task_WorkingWithJVMHeapSize-5f7fe4.html
Working With JVM Heap Size
Adjusting the JVM heap size settings can improve performance in some situations, however, the default settings are typically adequate for most situations. ... In the Administrative Console, select Servers, Server Types, WebSphere application servers, and click on your server in the resource list. Select the Configuration tab, and in the Server Infrastructure section expand Java and Process Management, and click Process definition.
🌐
Azul
docs.azul.com › prime › Heap-Size
Recommended Heap Size
The default value is 1.5625% of the total system memory or cgroup/container limit, and ranges from a minimum 128 MB to a maximum 2 GB. When ZST is installed, this parameter is ignored and the minimum heap size is equal to -Xmx, except when heap elasticity is enabled.
🌐
Blogger
javarevisited.blogspot.com › 2011 › 05 › java-heap-space-memory-size-jvm.html
10 points about Java Heap Space or Java Heap Memory
Heap in Java is generally located ... garbage collection works in Java. The default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM but its highly varies from JVM to JVM e.g....
🌐
Medium
medium.com › @maheshwar.ramkrushna › understanding-heap-size-and-its-impact-on-java-application-performance-d4c312bbd13c
Understanding Heap Size and its Impact on Java Application Performance | by Ramkrushna Maheshwar | Medium
May 25, 2023 - We recommend increasing the maximum heap allocation to 512 MB or 1024 MB when dealing with discovery ranges equivalent to a class B subnet, or in excess of 30,000 addressable devices. This is because the default maximum Java heap size is 256 MB, ...
🌐
Oracle
docs.oracle.com › cd › E74363_01 › ohi_vbp_-_installation_guide--20160224-094432-html-chunked › s66.html
2.7.2 JVM Options
Allocating too much memory can lead to lengthy garbage collection pauses and lengthy memory defragmentation (also known as compaction). That in turn may lead to system failures. Make sure that the maximum heap size does not exceed 8192 megabytes.