How to get free available memory in Java program
Continuing with our interest for java, I decided to write something about getting free avaialble memory in Java program. Below, i am putting the code snippet which will print the total and free memory at runtime to the console.
Pre-requisites to run this program
1.) You must have JDK 1.3 or above installed on your system.
2.) ClassPath must be set to point to the working directory.
If you are using an IDE like Netbeans or Eclipse, you might not be required to setup the environmental variables.
public class MemoryExp
{
public static void main(String[] args)
{
System.out.println("Total Memory"+Runtime.getRuntime().totalMemory());
System.out.println("Free Memory"+Runtime.getRuntime().freeMemory());
}
}
You can follow me on Twitter at http://twitter.com/vaibhav1981
Do stay tuned to Technofriends for more, one of the best ways of doing so is by subscribing to our feeds. You can subscribe to Technofriends feed by clicking here.
Related posts:
- Retro Roundup
- [Java] Program For Printing Limits of Primitive Data Types
- [Java] Reading a Webpage through URL
- [How-To] Create PDF,RTF,HTML document Using JAVA
- [How-To] Print Date/Time in a Given Format in Java