Error in question at The JavaRanch Rules Round-up Game
Cecilia Burman
Greenhorn
Joined: Jan 25, 2010
Posts: 6
posted
0
Hi
I just rounded up some cattle at The JavaRanch Rules Round-up Game. I noticed the following question:
(#16) Integer a=new Integer(5); Integer b = new Integer(5); What is the result of running if (a==b)
The real answr is true, not false
The Integer (maybe most wrapper classes) is an exception to the rule stated in the explanation. It does return true for low numbers as the following code-snippet shows:
Kind Regards, Cecilia
Stop climate change at any cost. An inhabitable world is worth the price.
http://www.newscientist.com/data/images/archive/2697/26971701.jpg
The discussion you refer to is exactly what I mean. Since the value (5) is lower than 127, the real answer is true, not false
Cecilia Burman
Greenhorn
Joined: Jan 25, 2010
Posts: 6
posted
0
I also found this question:
(#98) All exceptions ingerit from:
With the explanation:
"The Exception hierarchy begins at java.lang.Throwable"
IMHO all exceptions inherit from both Throwable and Exception. Isn't that so?
Cecilia Burman wrote:My mistake I did not realize the difference between "=0" and "=new Integer(0)"
No problem, after all you learnt something new
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
4
posted
0
I see that isn't your first post, but nobody has yet said this (sorry)
Cecilia Burman, welcome to JavaRanch
Cecilia Burman
Greenhorn
Joined: Jan 25, 2010
Posts: 6
posted
0
Thanks /Cecilia
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2782
2
posted
0
Cecilia Burman wrote:I also found this question:
(#98) All exceptions ingerit from:
With the explanation:
"The Exception hierarchy begins at java.lang.Throwable"
IMHO all exceptions inherit from both Throwable and Exception. Isn't that so?
:-)
/Cecilia
Not really. When people talk about "exceptions" or "exception handling", note the lower case, they often mean any Throwable. Like wise they often say "error" or "error handling" when they really mean any Throwable. The problem is that "throwable handling" isn't a term you could use outside the Java community, and it would be tedious to say "error and exception handling" instead. So informally, people use these terms more loosely. But if you capitalize the terms, it's clear you're talking about Error or Exception as specific Java classes, and the ambiguity goes away.