Oliver Grass

Ranch Hand
+ Follow
since Nov 02, 2000
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 Oliver Grass

Hi,
code will not compile cause continue can only be used in do-while, while-do and for-loops.....
cheers
Oliver
Hi Nasir,
the compiler checks if the integral value you pass to the char fits in a char. If this is the case, assignment is possible...
You can do a whereas a won't work.
If you try to create a Character-object, he doesn't make this check, it is required that you pass in a char... So if you wanna make a new Character(7) you have to explicitly cast the 7 to a char...
hope that helps,
as always, correct me if i'm wrong
cheers
Oliver
Hi Rajani,
i don't know if you're satisfied with this answer but this behavior is defined in the Language specification. You have to accept this...
hope that helps
cheers
Oliver
Hi Shan,
my guess would also be e)
in line 06 you have an object pointing to a string literal. This object is in the string pool. In line 07 you are referring to the same object!!! Since you're not creating the String-object with new, both of them referr the same String-Object.
In line 09 you set anObj to null, but locObj still points to the
"sampler". So this isn't eligible for the garbage collection, cause there is still a reference on it.
locObject is valid till the end of the block, which is at line 11. That's the reason why the answer is e)
Hope that helps
cheers
Oliver
Hi,
you can add a WindowListener to the frame...

Now you can close the window, when you click on the close button.....
hope that helps
cheers
Oliver
Hi Hemal,
there is an errata for the RHE saying that there should be two different colums, one for the methods and one for constructors. And they are also saying that only the access modifiers (public, protected, default and private) are allowed....
You can find the errate on the sybex-page....
cheers
Oliver
Hi Prasad,
if you assign 24 to a byte or short variable, this will work as long as the range of a short or a byte can cover the value. For example an byte b = 300 won't work. Compiler will detect, that he can't put 300 in a byte....


[B]Originally posted by Prasad Ballari:

[/B]


When you assign 24 to s, the compiler will know that 24 will never change during the runtime, its an integral literal....
But if you assign s to a byte b, compiler can never be sure, if s will always fit in the byte. That's the reason why he complains. If you change to everything is okay...
hope that helps
as always correct me if i'm wrong
Oliver
Hi Asmin,
hmmm, you have to read this RHE carefully
They are saying...

The Java language specifies 50 keywords and other reserved words which are listed in Table 1.1


The heading of this table only mentions java keywords, BUT there are keywords and reserved words....
cheers
Oliver
Sorry,
but bill is right....
Look at the JLS, chapter 3.9....
Keywords: one of.... const .... goto...
Every keyword is a reserved word, including const and goto (this has nothing to do if they are used or not, they are keywords).
Reserved word are mostly keywords, BUT there are some, which are NOT keywords BUT reserved...
These are the boolean literals true and false and the null literal...
hope that helps
Oliver
Hey Bosun,
are you sure???

Originally posted by Bosun Bello:
[For your second question, String s1="Hello"; is created in the string pool and is not eligible for garbage collection. while
String s2=new String("Hello") is created on the heap and is eligible for GC.


What has a string literal in the string pool to do with being eligible for garbage collection??? IMHO you can still say s1 = null and then s1 is eligible for garbage collection. The literal will stay in the string pool, but that's only how JVM optimizes string literals.
I'm not sure if your statement is completly right...
Perhaps someone can help or you could explain me, why do you think that s1 is not eligible for garbage collection....
cheers
Oliver

[This message has been edited by Oliver Grass (edited November 23, 2000).]
Hi Anand,
as Asim told you, this is an assignment to an Object with value null. So there is nothing special about...
You can do a without any problems....
BUT you will get a NullPointerException, if you invoke a method on that string, for example if you want to print out the length...

Hope that helps, cheers
Oliver
Hi,
sorry for the short answer before...
I will give a try, you have to correct me if i'm wrong. And i don't want to confuse people...
1) new String(" aa ");
this is in fact the copy-constructor of string. So first a string -literal is created (" aa "), then a new String-Object is created. Now this is the point where i'm not that sure....
Is the String-literal (" aa ") treated as an String-Object or not???
I would vote for yes, and so this creates in fact 2 Strings...
2) trim().
Cause there are whitespaces before and after the "aa", trim() returns a new String...
3) same with substring(), returns a new String-Object
4) replace() also, returns a new String-Object...
So, if you take the the two from the first one, plus the 3 more, you get 5....
Hope that helps,
as always correct me if i'm wrong
cheers
Oliver
Hi folks,
i just saw a little piece of code, which is interesting...
Wut happens when compiling and running the following prog

have fun
Oliver