Site icon TestingDocs.com

Write a Simple Java Program to know the Java version

Overview

In this tutorial, we will go through the steps involved to write a simple java program to display the java version on to the console window. We will use the System class. This class contains useful methods that we can use to access environment variables, defined properties etc.

For example:

System.getProperty() method.

This method gets the system property indicated by the specified key.

Code listing

package com.testingdocs.sample.Questions;
//www.TestingDocs.com
public class SystemInfoDemo {
  
  public static void main(String[] args) {
    System.out.println("Java Version = "+ javaVersion());
  }

    public static String javaVersion() {
        return System.getProperty("java.version");
    }

}

 

Run output

Exit mobile version