aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Explaint the ouput..." Watch "Explaint the ouput..." New topic
Author

Explaint the ouput...

Tarun Kumar
Greenhorn

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;
if(intBig==longBig){
System.out.println("True");
}else{
System.out.println("False");
}
}
}

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
Greenhorn

Joined: Apr 30, 2008
Posts: 26
Thanks Winay.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Explaint the ouput...