This site javatpoint is very useful for programming languages like JAVA,PYTHON,C,C++, Data Structures etc.Java learning Concept also provides technical materials , which are related to latest technologies. We provides very easy lectures to our viewers from beginning to advance level.We focus logical content instead of theoretical content.

Wednesday, 29 August 2018

Java Memory Management for Java Virtual Machine(2023)

Java Memory Management for Java Virtual Machine(2023)

If you want to learn how jvm works internally and how many memory it's occupied at the time of run.when we compile our program and run then jvm occupied some memory for class members like ,data types,variables,functions,objects etc.
Java application communicates with jvm by using Runtime object.Runtime class present inside java.lang package.
Based on our requirement we can create Runtime object.as follows.

Runtime r=Runtime.getRunttime();

After creating Runtime class object we can call memory methods.


class Test
{
public static void main(String[] args)throws Exception
{
Runtime r=Runtime.getRuntime();
double mb=1024*1024;
System.out.println("MAx memory inside jvm:"+r.maxMemory());
System.out.println(" total memory inside jvm:"+r.totalMemory());
System.out.println("free memory is inside jvm:"+r.freeMemory());
}

}


output:
MAx memory inside jvm:1890582528
 total memory inside jvm:128974848
free memory is inside jvm:127611672

Adbox