How To Check System Configuration Before Proceeding With Our Code In Java?

Spread the love
  • 1

The objective of this post is to check system configuration for running java codes. when it is exactly required??
Well lets say I have developed a program in Java-1.6, and used some code which got enhanced in that particular version.

  • Native platform Security (GSS/Kerberos) integration.
  • Java Authentication and Authorization Service (JAAS) login 
  • module that employs LDAP authentication
  • New Smart Card I/O API
  • Native security services technical article

Lets assume that this program will run on java -1.5 . Definitely the compatibility will not be there.

As per stack over flow

The compiler is not backwards compatible because bytecode generated with Java6 JDK won’t run in Java 1.5 jvm (unless compiled with the -target 1.5 flag). But the JVM is backwards compatible, as it can run older bytecodes.

So I guess they chose to consider the compatibility from the point of view of javac (as it is the part specific to the JDK), meaning that the bytecode generated can be run in future releases of the jvm (that is more related to the JRE, but also bundled in the JDK).

In brief, we can say:

    JDK’s are (usually) forward compatible.
    JRE’s are (usually) backward compatible.

Let us also assume , my program needs the below written…

  • Java version-java 1.7
  • OS-Windows XP
  •  and I have some requirement where the .class file should be in C drive.

if all of the above are matching then our program is good to go else we will simply say with the  configuration, this program will not run…

Lets see how:
In my previous post here..
I have shown how to get system properties.
From the list of properties we are only going to choose

  • java version
  • OS 
  • class. path
import java.util.Properties;

public class systemTest {

  * @param args
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  boolean b=false;
  Properties p=System.getProperties();
//get all the list of properties.
                String path=p.getProperty("java.class.path");
  String os=p.getProperty("");
  String javaVersion=p.getProperty("java.specification.version");
  if((path.indexOf("C:\")>=0||path.equals(".")) && os.equals("Windows XP") && javaVersion.equals("1.7"))
//checks the path contains C drive,also checks for OS or java version
    System.out.print("We can proceed");
    System.out.print("We can not proceed");

. (dot means present working directory.)
Windows XP
We can proceed

Now if the java version is 1.4 (running)in the client machine. It should say “We can not proceed”

By this way we can achieve the precondition cases for running our tests.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1


Please enter your comment!
Please enter your name here