Thursday 7 January 2016

Memory in Java

Q:-Write a program in Java. To find out memory statistics available for Java Virtual Machine.





Code

Source Code
import java.io.*;
class Memory
{
public static void main(String[] args)
{
System.out.println("Total Memory for JVM(Java Virtul Machine ) " + "\t\t\t"+Runtime.getRuntime().totalMemory());
System.out.println("The maximum Memory that JVM(Java Virtual Machine) can use is\t"+Runtime.getRuntime().maxMemory());
System.out.println("The amount of free memory in Java Virtual Machine is: \t\t"+Runtime.getRuntime().freeMemory());
}
}

Ouput

[student@localhost memory]$ javac Memory.java
[student@localhost memory]$ java Memory
Total Memory for JVM(Java Virtual Machine) 31391744
The maximum Memory that JVM(Java Virtual Machine) can use is 620756992
The amount of free memory in Java Virtual Machine is: 30895944
[student@localhost memory]$
 

No comments:

Post a Comment