Does order matter?

Does order really matter? I admit this topic is probably a bit too wide. So lets put it in more precise way.
Does the order of condition within one single block of if statement matter on Java? Ordinary if statement can be written like this:
5213F42B-483B-4240-8190-678075CB0542.png
Computation only triggered when both condition met. So does the order matter? Cuz both condition gonna be examine for check anyway. This is what I thought till saw an article on D-zone week before.
It turn out the order does matter giving a situation that its costly for proceed both validation and crossCheck. And JVM is smart enough to stop as validation return false, cuz there is no way to have a true as return when either side in such situation. So in this case crossCheck won’t be triggered at all if validation return false.
This allow u to save resources when function CrossCheck ( ) actually expensive like: crosscheck need to fire a DB connection or RPC to process.
That’s I won’t execute both method call and both result into if statement for examination cuz extra work is done in some case.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s