In this section of Java Example, you will see how to get the memory size using Java programming language. This is a very simple example and you can easily learn it.
In this Java Get Memory Size example, we have created a class called Memory and defined all the functionality in it to show the memory size. System.out.println is used to print the result on the command prompt.
Code to Get Memory Size in Java
public class Memory {
public static void main(String[] args) {
System.out.println("Total Memory"+Runtime.getRuntime().totalMemory());
System.out.println("Free Memory"+Runtime.getRuntime().freeMemory());
}
}
Output will be displayed as:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java Get Memory View All Comments
Post your Comment