aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem wrapper value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem wrapper value" Watch "Problem wrapper value" New topic
Author

Problem wrapper value

Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
public class DemoTest{
public static void main(String[]args){
int i = Integer.MAX_VALUE + 1;
System.out.println(i);
}
}
This program run successfully.Why no error generated?


"Control time instead of letting time control you."
sweta doshi
Greenhorn

Joined: Jan 04, 2008
Posts: 14
Hello ,

Look at the output ...it gives you " -2147483648 " which means it goes back to the Integer.MIN_VALUE . And hence does not throw any error .

Thanks
Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
You could not understand my question?
compare with
int i = 2147483674 + 1
Now what happing?
sweta doshi
Greenhorn

Joined: Jan 04, 2008
Posts: 14
Hi ,

You are trying to say that it should normally add 1 to the highest value which should result in an error simply because it is no longer in the range of int.. right ?

Thanks
sweta doshi
Greenhorn

Joined: Jan 04, 2008
Posts: 14
Hi ,

int i= 2147483647 + 1;
If i use the above , it throws a compiler error saying that it is out of range since int cannot hold it . You already trying to stuff something into an int that is not appropriate for int. Rather use long . I hope this answers you .

Thanks
Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
Dear sweta doshi you again tell the same thing.

Look at my first post. here i use wrapper Integer.MAX_VALUE +1 and assign the value into the int variable. But in that case it generated no error why?
Narendra shah
Ranch Hand

Joined: Feb 28, 2007
Posts: 51
Hi Dear. Which Compiler are you using. It do not throw any compiler error. I had tried with all 1.3,1.4,5,6. No errors in compilation or runtime.


Narendra Shah -- SCJP 5
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Prasun as you mentioned in post you are trying to add 2147483674 and not 2147483647 to 1 and assign to i. Here 2147483674 is clearly out of range for int since its range is from -2147483648 to 2147483647
The below code compiles fine.

May you got confused with the MAx value.


SCJP, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem wrapper value