I want to see how many objects Java creates when my program starts.
My intention is that if I use the code String s = new String("Hi");, I want to see how many objects Java creates. Later I want to try withString news = "Hi";
This is my sample program:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String str = new String("Hi");
Scanner s = new Scanner(System.in);
s.nextLine();
}
}
I use it Scanneronly so that the program does not interrupt.
I went through the SO message How to find the number of objects on the heap and tried to use it jvisualvm, but the tool does not give an account of my objects created in my class. I also do not understand how to get the actual number of objects based on the image below.

When I tried to use the command jmap -heap <pid>, I get below error:
ID 15101, , ... process: sun.jvm.hotspot.debugger.DebuggerException:
eclipse Debug as, , .