dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Jul 5, 2021

How to List Memory Types in Java

Welcome back to another Java programming tutorial. Today, Java developers will learn how to list the available memory types in Java by using the java.lang.management.MemoryType package utility. We begin by importing the java.lang.management package, then create a class to search for the available memory types before we print them out to the console. Examples of memory types include heap and non-heap.

Try out the following code to learn how to list the available memory types using Java:

*/

import java.lang.management.MemoryType;

public class MemoryTypesEx
{
	public static void main(String args[])
	{
		MemoryTypesEx memoryTypesEx = new MemoryTypesEx();
		memoryTypesEx.proceed();
	}
	
	private void proceed()
	{
		for (MemoryType memoryType : MemoryType.values())
		System.out.println(memoryType);	 
	}
}

/*

When you run this code you can expect the following output. Note that this might vary depending upon the setup of your computer:

[root@mypc]# java MemoryTypesEx
Heap memory
Non-heap memory
MS Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date