Statement Java If and Or


The following statement is working without any issues, but please can someone explain why, I was under the impression there should be an additional set of brackets before the &&? However, even with the () missing it still works.

if(returnt.getInt("date", iLoop) == Util.getBusinessDate()
     && returnt.getInt("ins_type", iLoop) == Ref.getValue(SHM_USR_TABLES_ENUM.INSTRUMENTS_TABLE, "DEPO")
     || returnt.getInt("ins_type", iLoop) == Ref.getValue(SHM_USR_TABLES_ENUM.INSTRUMENTS_TABLE, " DEPO2"))

My old university professor used to say, perhaps rather inappropriately, that excess parentheses are for quiche eaters and for girls.

Learn your operator precedence tables by heart. Your code is equivalent to

if (((returnt.getInt("date", iLoop) == Util.getBusinessDate())
    && (returnt.getInt("ins_type", iLoop) == Ref.getValue(
      || (returnt.getInt("ins_type", iLoop) == Ref.getValue(

i.e. == is evaluated first, then &&, then ||. Note that the latter two are short-circutted, so evaluation stops once the result is known.

As you get more experienced you will find the version I've pasted up to be considerably more difficult to read.