Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// File: JvmDemo.java // Demonstrates compilation units, packages, and basic JVM information package com.example.intro; // maps to directory: com/example/intro/ public class JvmDemo { public static void main(String[] args) { // ---- Runtime / JVM info ---- Runtime rt = Runtime.getRuntime(); long maxMemory = rt.maxMemory() / (1024 * 1024); // convert to MB long totalMemory = rt.totalMemory() / (1024 * 1024); long freeMemory = rt.freeMemory() / (1024 * 1024); int processors = rt.availableProcessors(); System.out.println("=== JVM Runtime Information ==="); System.out.printf("Max heap memory : %d MB%n", maxMemory); System.out.printf("Total heap memory: %d MB%n", totalMemory); System.out.printf("Free heap memory : %d MB%n", freeMemory); System.out.printf("Available CPUs : %d%n", processors); // ---- System properties ---- System.out.println(" === Key System Properties ==="); String[] keys = {"java.version", "java.vendor", "os.name", "user.dir"}; for (String key : keys) { System.out.printf("%-20s = %s%n", key, System.getProperty(key)); } } }
Result
Open