This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Explaint the ouput... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Explaint the ouput..." Watch "Explaint the ouput..." New topic

Explaint the ouput...

Tarun Kumar

Joined: Apr 30, 2008
Posts: 26
public class T6
public static void main(String[] args)
long intBig = Integer.MAX_VALUE + 1;
long longBig = Integer.MAX_VALUE + 1L;

It's output is False. how the output is coming.

Tarun Kumar
winay Kumar
Ranch Hand

Joined: Aug 13, 2007
Posts: 34
Hi Tarun,

in this first statement "long intBig = Integer.MAX_VALUE + 1;" its directly incrementing Integer max value by 1 which in turn its going to negative value ie Integer.MIN_VALUE and then its assigning to long data type.

where as in second statement "long longBig = Integer.MAX_VALUE + 1L;" first its converting to long, then incrementing by 1 and then assigning.

if you print intBig, longBig its giving -2147483648, 2147483648 respectively.

Winay Kumar<br />SCJP 5.0
Tarun Kumar

Joined: Apr 30, 2008
Posts: 26
Thanks Winay.
I agree. Here's the link:
subject: Explaint the ouput...
It's not a secret anymore!