kevinn lee

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

Recent posts by kevinn lee



output


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

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?

thanks
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html
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.

Henry


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
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?
thanks.

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.
thanks

Sandra Bachan wrote:Hello,



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?
thanks
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.
thanks