9

How can I find the name of currently running java virtual machine name? I want to get it from java API.

Thanks

Shamim Ahmmed
  • 8,265
  • 6
  • 25
  • 36

5 Answers5

12

Since you didn't really specify what you are looking for, take a look at these System Properties:

  • "java.vm.name"
  • "java.home"
  • "java.version"
  • "java.vendor"
  • "java.specification.vendor"

Like this:

System.out.println(System.getProperty("java.vm.name"));
System.out.println(System.getProperty("java.home"));
System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.specification.vendor"));
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
5

There are two kind of JVM names namely:

  1. Java Virtual Machine implementation name : Java HotSpot(TM) Client VM
  2. Java Virtual Machine specification vendor : Oracle Corporation

Type code in java program and see output:-

 System.out.println("Java Virtual Machine specification version  : "+System.getProperty("java.vm.specification.version")); 
 System.out.println("Java Virtual Machine specification vendor : "+System.getProperty("java.vm.specification.vendor"));
 System.out.println("Java Virtual Machine specification name : "+System.getProperty("java.vm.specification.name"));
 System.out.println("Java Virtual Machine implementation version : "+System.getProperty("java.vm.version"));
 System.out.println("Java Virtual Machine implementation vendor : "+System.getProperty("java.vm.vendor"));
 System.out.println("Java Virtual Machine implementation name : "+System.getProperty("java.vm.name"));

refer https://docs.oracle.com/cd/E15289_01/doc.40/e15062/sysprop.htm

see output of java -version

To know ur JVM vendor: type java -version in cmd and see third line of it.

eg:

C:\Users\jack>java -version

java version "1.8.0_74"

Java(TM) SE Runtime Environment (build 1.8.0_74-b02)

Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)

Draken
  • 3,134
  • 13
  • 34
  • 54
2

If you are trying to get the process id of the current process you can do this.

How can a Java program get its own process ID?

Community
  • 1
  • 1
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

There is a variety of properties you can get with System.getProperty(), java.vm.name seems like what you need.

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
0

System.getProperty("java.version") should do the trick