1

we run java program in cmd using java , same way for finding installed java version we use Java -version in cmd, So how does it gives us version details? Is there any Version class defined in java API ?Its seems funny Question though

2 Answers2

5

Use

System.getProperty("java.vendor")
System.getProperty("java.version")
System.getProperty("java.vm.vendor")
System.getProperty("java.vm.name")
System.getProperty("java.vm.version")
System.getProperty("os.name")
System.getProperty("os.version")
System.getProperty("os.arch")

And for getting the default character encoding

new java.io.OutputStreamWriter(new java.io.ByteArrayOutputStream()).getEncoding()
Serg M Ten
  • 5,568
  • 4
  • 25
  • 48
0

Java stores the version into the java.exe. In case you want to try for yourself just open the java.exe into any text editor or hex editor and you will find version written inside it.

Akshay Chordiya
  • 4,761
  • 3
  • 40
  • 52