ramesh vardhan

Greenhorn
+ Follow
since Jun 21, 2005
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 ramesh vardhan

Hi all,
Happy to tell you that I scored 90% in SCJP 5.0.

Thanks to K&B for the wonderful book,
this is the only preparation I did.
And a big thanks to JavaRanch,
active participation of many helped a lot.
16 years ago
Thanks John.
Yeah, behavior is same when I did not use any IDE.Probably the optimization for an empty for loop is set on my IDE.
John said it right.
Nothing can be said until you do not handle the exception!

Possibly null is being returned by the method listFiles.

About the peculiar behavior of enhanced for loop like:
Code 1:
11.String s[]=null;
12.for(String ss : s){
13.System.out.println("Simple Stmt!!");
14.}
Throws a null pointer exception at runtime, at line 12.

Code 2:
11.String s[]=null;
12.for(String ss : s){
13.//System.out.println("Simple Stmt!!");
14.}
No exception thrown at runtime.

Can somebody please help in this regard.
For the purpose of explanation i used s2[ind] instead of s2.charAt(ind).

Please do not confuse.Sorry if I have already created.
The comparator arrange the strings in reverse order as s2[ind]-s1[ind] is being done.i.e when s2[ind] is 'b' and s1[ind] is 'a', then the compare method returns positive integer('b'-'a') saying 'b' > 'a'(reverse order).

And the character under concern is of index 1.so the order '0'>'g'>'a'.
Otherwise - Good>Ugly>bad.

Hope this is clear.
/* Code bit */
int[] arr1={1,2,3};
int[] arr2=new int[4];
arr2=arr1;
System.out.println(arr2[3]);
---
The above code throws a java.lang.ArrayIndexOutOfBoundsException.

Code insight:
1.Two array objects were declared and initialized.
so two references and two objects are created.
2.Then the reference of arr2 is made to point to the object of arr1 by assigning its reference.
3.Hence after assignment two references are pointing to one object,making
the empty array eligible for Garbage Collection.
4.arr2 has only 3 elements and max index is 2,hence the exception.
Its simple assignment of objects to references.No value copy is made or element copy is done.
Hope this clears your doubt.