Is there Java interpreter optimization of if (expressions) ?

My Java code,

for my game, I'd like to reduce computing time,

I have a section...

serverMode =0 means the server is waiting for all the clients to join, 69 is the code for a client-join message

          if ((serverMode==0)&&(command==69)) {// JOIN MESSAGE

I then want an  } else if (serverMode==1)  { //player move message

Will the  if (servermode==0... aspect immediately jump to the else ServerMode==1 query?

ServerMode = 1 once all the players have joined, so once the game starts, I don't need it to check if command is 69.
Does the interpreter do any optimization, or recognize shortcuts?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you mean if serverMode is not zero , then it will not check the second part - that is truye - taht's how java will be working by deafualt
>>Will the  if (servermode==0... aspect immediately jump to the else ServerMode==1 query?

Yes, if serverMode doesn't evaluate to zero. It won't even bother evaluating 'command'
You don't need to do anything special - java is doing that in the ordere ofmnlogical statements smartly
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

It is just like CEHJ said.

The "&&" is a short circuit operand.

So in your expression:

>> if ((serverMode==0)&&(command==69))

If serverMode == 0 is false, the && operand won't evaluate command=69

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Java does it in a smart way, that's why it allows you such very common constructions:

if(myObject != null && myObject.getAge() != 5) {....}

in this case if myObject is null java will evaluate the whole thing as fasle and skipp the second comaprison altgether and thus avoid NullPointerException, which would otherwise happen
if it  evaluation of those parts would have beeen done indpendnetly (and if myObject happens to be null and then it would have tried to invoke method on null
with resulting nullpointer exception)

We are using this all the time, so you don't need to to do anything specific to avoid second condition evaluation

By the way similar thing happen with OR condition( ||  ) - if the left part is true - java would come with the overall reslt true
and not bother to go the rest of the comaprison


You can read more details about how Java eveluates logical expressions here:
beavoidAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.