This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

kevinn lee

Ranch Hand
+ Follow
since Feb 15, 2010
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kevinn lee


what type of referrence variable can refer to "o" other than Object type?

why doesent compiler allow to use a pre declared variable and a variable declared within the for loop together?
code compiles when both are declared within and when both are declared out of the loop.
or is it because line "i=0,int j=90;"it self is faulty when taken alone?

according to this document

Subsequent characters may be letters, digits, dollar signs, or underscore characters.

"#" is not a letter,digit,dollar sign or an underscore.Thats why your identifier is illegal.

Henry Wong wrote:

kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?

The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.

Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.


thank you henry

I came across this in a certain mock exam.Are we supposed to know things like this for the exam?

why doesnt line 1 one causes a runtime exception while line 2 does?
Thanks a lot Henry

but at runtime isnt it the same String literal "abc" that lies in the String pool that both s5 and s3 are pointing to?

can someone explain the reason for the two different outputs?what difference does s3 have because s2 is final?

Jim Hoglund wrote:The string pool mechanism is at work here. To conserve memory, the compiler will
at times, share a string object if sX.equals(sY). Apparently in your case it put "abc" in
the pool and used it again. (Maybe for s1, s3 and s4).)

Jim ... ...

but it seems as if "abc" is not shared here since "s1==s3" turns out to be false.

Sandra Bachan wrote:Hello,

go to the link given by Ravinderjit
it explains what is special about Strings
thanks for replying

Ravinderjit Singh wrote:Because will create a new String object, means s1 and s3 are referring to two different objects.

you mean

String s3=s2+"c";

is like

rather than

is it?
compiler compiles any code unless it knows exactly that the particular casting is impossible.
In your case there can be a class which implements both the interfaces.Then both i1 and i2 can refer to an object of that class and the casting between I1 and I2 makes sense.

why doesnt line 2 give "true"?I mean after line 1 doesn't s3 refer to the same string literal "abc" in String constant pool that s1 is refering to?
Or is there a different mechanism how a new String is created when "+" operator is used.Please explain.