I am wondering if you have looked at this link[1]. It does not contain Java code but you should be able to run the “curl” command and receive the metadata you want.
It does state :
“Every instance stores its metadata on a metadata server. You can query this metadata server programmatically, from within the instance and from the Compute Engine API. “
Does this help?
[1] Storing and retrieving instance metadata :
https://cloud.google.com/compute/docs/storing-retrieving-metadata
I was wondering if you have seen this link[1]. It may be of interest to you.
[1] Method: instances.get :
https://cloud.google.com/compute/docs/reference/rest/v1/instances/get