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
Asked
Active
Viewed 112 times
1
-
4No, it's not in the API. It's just printing values baked into the `java` binary when it was compiled. – Andy Turner Nov 17 '16 at 09:25
-
1Related: [Getting version of java in runtime](http://stackoverflow.com/q/2591083/3788176). – Andy Turner Nov 17 '16 at 09:26
-
See this answer: http://stackoverflow.com/a/13851817/4491066 – Adam Nov 17 '16 at 09:28
2 Answers
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
-
1Even the default character encoding may be got from the standard System Property "file.encoding". – Little Santi Nov 17 '16 at 23:20
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