Let me quote @Rup here for your first question:
It's not really println
that's evaluating it - if you assigned it to a variable and printed that you'd get the same result.
To add onto that, it's Java that's evaluating that expression. If you put that into any other function it would work as well. It's part of Java — it's called "nested expressions."
For your other question see @user000001's answer, and there was also a discussion in the comments that added onto that (I have edited it to make it more clearer):
It's not clear at all normally the result is 15. b
has been incremented.
In other words why Integer b = 4; System.out.println(b++ );
gives 4 even though b
has been incremented. – BenMansourNizar
@BenMansourNizar This is because you are using the postfix operator (see http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html.) With b++
the value is first used, and then incremented. If you use ++b
, the value will be incremented before being used. – user000001 Jun 2 '13 at 17:58
Thanks a lot, user0000001 :) - BenMansourNizar
I hope you and other people find this information helpful, I really just quoted a bunch of stuff and commented on it :P