With correct indentation ( Ctrl + Shift + F in Eclipse) you see why your result seems to be 2 != 2 :

class A { public static void main(String[] args) { if (1 == 1) // true if (2 == 2) // true if (2 != 2) // false System.out.println("2 != 2"); else System.out.println("2 != 2"); // is actually 2 == 2, gets executed else System.out.println("1 != 1"); // is actually 2 != 2 } }

You probably have a Python background where spaces matter. In Java they don't matter and can be placed without having an effect on execution. If you write if statments like this, Java will nest them internally and not by indentation (just like HTML tags - last if, first else and so on).