aspose file tools*
The moose likes Beginning Java and the fly likes dead code and Unreachable code diff Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

dead code and Unreachable code diff

veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67






please tell the difference.

Thanks
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Veena ,

The first code sample you provided is Dead Code and it will not compile at all ! The second code sample does compile but a warning is issued by your IDE . This is the major difference . Apart from that , the reason why the code in the second code compiles is that you are using varibales and the java compiler 'thinks' that maybe these variables will change on runtime. However, when you use the same code and replace variables with actual values , the compiler knows already at compile time that this code will not be reached ever.

Another thing I would like to point out is that if you mark your variables as final in the second code sample, you will again get compile time error ( instead of warning ) because of the "final" nature of the variable.


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
veena - as saif's reply refers to you using variables in the second code sample, when in fact there aren't any, I'm assuming you have edited the code. Please don't do this - it makes the rest of the thread meaningless.


Joanne
veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
hello,
asif

thanks for the reply, i had made editing mistake in the code so i have edited the code, based on that you answer,please.

the 1st sample code compiles n run successfully. No doubt. statement after else not considered as not reachable code, where as in while loop, it is.

that is the Question.

why it behaves different in if and while loop
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
veena bijur wrote: . . . i had made editing mistake in the code so i have edited the code, based on that you answer,please. . . .
No, that is the wrong thing to do. As Joanne Neal has already said, it makes the thread incomprehensible.

To avoid further confusion, I am closing this thread, and suggest you post a new thread with what you are asking about, without “editing mistake”s. Then we can all see what we are really dealing with.
 
Consider Paul's rocket mass heater.
 
subject: dead code and Unreachable code diff