Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

August 20, 2007

Aha! Java

Jon Bentley talks about the Aha! Insight in his book Programming Pearls.

I got 2 such 'Aha!s' today :

1) Java does support Short Circuit Operators(or short circuit evaluation)
public class myTest2 {

public static void main(String[] args) {
myTest2 sct = new myTest2();
if (sct.isTrue("left") || sct.isTrue("right")) {
//you may swap the 'left' and the 'right' and observe the behaviour
System.out.println("Expression is true.");
} else {
System.out.println("Expression is false.");
}
System.out.println("All done.");
}

public boolean isTrue(String msg) {
System.out.println("in isTrue (arg = '" + msg + "')");
if (msg.equals("right")) return true;
else return false;
}
}


2) Loop unrolling leads to instruction level parallelism. But am not sure whether this will have any effect on the way Java is architectured. I presume that stack based architectures(Java/JVM) do not have any effect on ILP.

Any thoughts or Ahas!!!!!