aspose file tools
The moose likes Beginning Java and the fly likes If Statement Limitation? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "If Statement Limitation?" Watch "If Statement Limitation?" New topic
Author

If Statement Limitation?

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
What is the limitation of using the if statement?
long longMaxValue;


if(longMaxValue >=9223372036854775807)
{
}

This would flag an error, stating that "integer number is too large" when the longMaxValue is declared type long.

But if I write it this way, it wouldn't flag an error:
if(longMaxValue >= Long.MAX_VALUE)
{
}

Why?

[ July 17, 2005: Message edited by: Karen Baog ]

[ July 17, 2005: Message edited by: Karen Baog ]
[ July 17, 2005: Message edited by: Karen Baog ]

amerzil co-ed student<br />"Praise be the Code"
Steve Simon Joseph Fernandez
Ranch Hand

Joined: Jul 17, 2005
Posts: 35
Hi Karen,

You should postfix 'L' to the number to indicate that it's a long constant. I think by default, all numeric constants are taken by java as int unless otherwise specified. This works:



_steve.
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
The two numbers you posted are the same - the character at the end of the first one is a lowercase 'L', not a one, used to indicate the value is a long.

But to be absolutely sure of the value, why don't you just do this:
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Steve Simon Joseph Fernandez:

I think by default, all numeric constants are taken by java as int unless otherwise specified.
_steve.


Absolutely right. One of the few things I still remember from SCJP preparation


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: If Statement Limitation?
 
Similar Threads
Desperate for Answer on Datagram Address Parameter
OutOfBoundsException Error
Closing/Opening again a Socket
Datagram sockets HELP NEEDED!
xsd:sequence, where minOccurs="0"