megha gupta

Greenhorn
+ Follow
since Nov 23, 2000
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 megha gupta

Here is a method, which creates a number of String objects in the course of printing a count down sequence.
1. public void countDown() {
2. for( int i = 10 ; i >= 0 ; i-- ){
3. String tmp = Integer.toString( i );
4. System.out.println( tmp );
5. }
6. System.out.println("BOOM!");
7. }
When the program reaches line 6, how many of the String objects created in line 3 are eligible for garbage collection? Assume that the System.out object is not keeping a reference.
The solution is none , but shudn't it be 9.
Everytime a new string object is assigned to temp and the previous one is dereferenced ?
TIA
Megha
Thanks Kathy,
That's what I thot but was not really sure if my fundas on short circuit operators were clear.
Megha
Hi , I am new here to post a message, but have been visiting javaranch for quite sometime
My query from JXAM:
Given the following definition:
String s = null;
Which code fragment will cause an exception of type NullPointerException to be thrown.
if ((s != null) & (s.length()>0))
if ((s != null) && (s.length()>0))
if ((s != null) | (s.length()>0))
if ((s != null) | | (s.length()>0))
None of the above.
The JXAM solution says 1, 2, 3, 4 are correct ans, however I feel the solution is wrong.
2 does not throw an exception .
Also I am not clear about the question.
Can someone explain to me please.
Thanks
Megha