1-what is the difference between x++ and x+=1 in the for loop iteration?such as saying for(int x=0; x< 3 ;x+=1)
for(int x=0; x< 3 ;++x)
for(int x=0; x< 3 ;x++) how the 3 cases output the same value for x for each iteration.
2-what make the code unreachable in the try/catch/finally/code after finally code ??
3- as i understand when we try to deserialize transient variable , it gets its default value of its datatype , ok what about if that transient variable was also final ?? and if this information are wrong ,would anyone can confrim me?
this questions has no source ,as this is from my mind ...
SCJP Pass 85%....
Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened
Heba Mahmoud wrote:1-i think there is a difference between ++x and x++... how the value become the same in iteration ??
The increment part of the for loop is evaluated completely before the condition is checked, so it doesn't matter if you use ++x or x++
Heba Mahmoud wrote:2- what about that case of unreachable code ,.. i think that it should the complair fails .. but it doesn't.
x is not a constant, so the compiler cannot detect its value at compile time so doesn't know that the if condition is true and the println statement is not reachable. Unreachable code with if conditions works differently then we think, see this post by Henry. But don't worry, such details (which Henry pointed out) won't be tested in the exam.
Heba Mahmoud wrote:3- when say transient int value =8; after deserialize it becomes 0 as i understand , may be i am wrong
so when it is final , what do you think it will be ?
venkat ga wrote:
Please explain about final transient private int b=10; some internal mechanism.
The variables which are transient which are not serialized. but if i use fianl why serializing is happening?
Final variables, that are assigned to a compile time constant, at the same time of the declaration, are also compile time constants. You can even argue that the variable probably doesn't really exist, as the compiler replaces it with the constant, whenever it is used.
Anyway, move the assignment to a instance initializer, or a constructor, and you will see that it is not serialized.
Venkat in the future please start a new topic for your problem by clicking . The original topic had nothing to do with your problem, so the question is not appropriate in this topic...
Joined: Feb 14, 2010
If it is, i am sorry.
But as per Heba Mahmoud (3rd question), i got this doubt. so i continued here.
because i am new to this forum.
Can you please give some more suggestions, how should i effectively follow this forum.
Venkat, I actually didn't realize that your question was indeed related to the original question. So posting in this same topic isn't a problem. See How To Ask Questions On JavaRanch for other forum rules...
Joined: Feb 14, 2010
Thanks alot Ankit, The link which you have given is very good. i will go through it once.