T
timjowers
Does a way exist to instruct the Java compiler to compile code only
if a certain version of Java is supported? For example, I may want to
measure with milliseconds in Java 1.4 or nanoseconds if I'm running in
Java 5.
import java.io.IOException;
public class JVMLoadTimeRunner {
public static void main(String[] args) {
long start = System.currentTimeMillis(); // only compile this line
in Java 1.4
//long start = System.nanoTime(); // only compile this line in Java
5
try {
Process newP = Runtime.getRuntime().exec( cmd );
newP.waitFor();
long end = System.currentTimeMillis();
System.out.println( "Process Execution took " + (float)(end-start)/
1000F + " seconds" );
// Java 5
// System.out.println( "Process Execution took " + (float)(end-
start)/1000000000F + " seconds" );
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
System.out.println( "Process wait threw an Exception" );
e.printStackTrace();
}
}
}
if a certain version of Java is supported? For example, I may want to
measure with milliseconds in Java 1.4 or nanoseconds if I'm running in
Java 5.
import java.io.IOException;
public class JVMLoadTimeRunner {
public static void main(String[] args) {
long start = System.currentTimeMillis(); // only compile this line
in Java 1.4
//long start = System.nanoTime(); // only compile this line in Java
5
try {
Process newP = Runtime.getRuntime().exec( cmd );
newP.waitFor();
long end = System.currentTimeMillis();
System.out.println( "Process Execution took " + (float)(end-start)/
1000F + " seconds" );
// Java 5
// System.out.println( "Process Execution took " + (float)(end-
start)/1000000000F + " seconds" );
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
System.out.println( "Process wait threw an Exception" );
e.printStackTrace();
}
}
}