top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find memory usage using Java program?

+1 vote
358 views
How to find memory usage using Java program?
posted Mar 31, 2016 by Vijay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

For memory usage you can use following command:

long total = Runtime.getRuntime().totalMemory();
long used  = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
answer Apr 3, 2016 by Shahsikant Dwivedi
Similar Questions
+2 votes

Java does not have sizeof operator now my question is How to find out how much memory is used by an object in Java?

+2 votes

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

...