Breaking News
Home / Java / Java Snippets / How to progamatically get the Java version?

How to progamatically get the Java version?

Snippet

The key here is to use the system property java.version and get minor and point version.

 

  1. public class CheckVersion {
  2.   public static void main(String[] args) {
  3.     String version = System.getProperty(“java.version”);
  4.     char minor = version.charAt(2);
  5.     char point = version.charAt(4);
  6.     if(minor < ‘4’ || point < ‘1’)
  7.       thrownew RuntimeException(“JDK 1.4.1 or higher “ +
  8.         “is required run this app”);
  9.     System.out.println(“JDK version “+ version + ” found”);
  10.   }
[pb_builder]

Check Also

How to parse ShoutCast/IceCast Stream Metadata in Java?

Snippet StreamScraper is a java library that can be used to harvest streaming metadata (current …

Leave a Reply