Yesterday one of my good friends, to whom I am teaching java , asked me that how can we find which version of JVM  and JRE the user has installed as well as what are its class and library path and java home?

 I was also intrigued as I have already been asked this question once before in an Interview . At first it seems like a normal and easy question which could be simply tackled by saying check environment variable for class path and write javac –version (I’m assuming that you know this) in your command prompt. But what if instead of answering this question bluntly you have to answer this from the point of view of programming. After all you are a programmer and this question is also asked by one. 

That’s why I thought to share this experience with you about how you can face this question if someone asks you, by writing a few simple lines of codes. 

Let’s check out what we have at our disposal and how we can use it.

In java we have a class by the name of Properties in Java.util package which is the answer to this question. (If you know any-other way then please feel free to share). So let’s check out the code  

1 import java.util.Properties;
2 public class PropDemo {
3 public static void main(String[] args) {
4 Properties prp = System.getProperties();
5 prp.list(System.out);
6 }
7 }

Here in line 4 we are retrieving the set of properties whereas line 5 prints the properties using the list method of properties class

You just have to write two lines and java will give you every single detail of java installation. Isn’t it cool?

READLIKE and SHARE with others so that they can also learn this neat trick.