Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Sujatha Musunuri

Greenhorn
+ Follow
since Oct 23, 2007
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 Sujatha Musunuri

Hi,

Today, I passed SCJP 1.5 with 93%. Answered 65questions correctly out of 72.
Thanks to all of you for your quick responses to my postings!!

Thrice, I read K &B book, understanding each & every topic and did the Master exam & bonus exam in the CD. Whenever I'm not clear abt any topic, used to test that by writing small programs in eclipse. Thatz it.

once again thanks to U all...
-Sujatha
14 years ago
Sorry to bother...got the answer.
Are interfaces by default 'public'? or do we need to declare them public explicitly every time?

Can I declare

interface Foo{
// some declarations
}

or is it must that I need to declare that using 'public' as follows?

public interface Foo{
// some declarations
}

--Thanks
@Freddy Wong : Thanks for the link.
@Kelvin Lim: Thanks for the example. I got it now.
Following is a question from K&B mock exam.

import java.util.*;

class Comp2{
public static void main(String args[]){
String[] words = {"Good", "Bad", "Ugly"};

Comparator<String> best = new Comparator<String>(){
public int compare(String s1, String s2){
return s2.charAt(1) - s1.charAt(1);
}
};

Arrays.sort(words, best);
System.out.println(words[0]);
}
}

ANS: Good

I'm always confused with Comparator. I could not get what exactly the s2.charAt(1) - s1.charAt(1); will do. How exactly it'll reverse the list? If it reverses the list then the list should be {"Ugly", "Bad", "Good"}. In this case, the words[0] should be-- Ugly.

Anyone, pls. clarify this to me - How the output is 'GOOD'?
324th page of K&B:

It is not enough to be final. Case Argument should be compile time constant.

final int a = 1;
final int b;
b=2;
int x=0;
switch(x){

case a: //ok
case b: //compiler error

}

Can some one clarify me the above example? Why is it giving compiler error for the case argument 'b'. What exactly does the 'compile time constant' mean?

-Thanks
11. public void addStrings(List list) {
12. list.add(�foo�);
13. list.add(�bar�);
14. }

What must you change in this method to compile without warnings?

A. add this code after line 11:
list = (List<String> list;
B. change lines 12 and 13 to:
list.add<String>(�foo�);
list.add<String>(�bar�);
C. change the method signature on line 11 to:
public void addStrings(List<? extends String> list) {
D. change the method signature on line 11 to:
public void addStrings(List<? super String> list) {
E. No changes are necessary. This method compiles without warnings


The Ans is D. But I think the answer is E. please correct me if I'm wrong.

-Thanks
Hi Jitendra Jha,

I got it now...Thanks alot for your explanation.
14 years ago
Hi,

Just going through the sample questions got from web.
Can someone explain me the result of the following program, placed at:

http://picasaweb.google.com/sujathalooks

The Answer for that question is F.

Thanks in advance.
14 years ago
1. public class Boxer1 {
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x=i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) {
9. new Boxer1(new Integer(4));
10. }
11. }

The Ans for this is 'NullPointerException' at runtime. Can some one let me know why is it giving that Exception?
Yes..the answer for this should be:
Derived.amethod()
99
Derived.amethod()

But I thought that it'll print like this:
Base.amethod()
99
Derived.amethod()

becoz, when we are instantiating the Derived class, the default Derived constructor will be called, which calls the super (Base) constructor.
Since Base constructor is calling the amethod(), it should call amethod() of class Base and should print "Base.amethod()". But it is calling "Derived.amethod()"............can any one clarify this to me?
Yeah Venkatesh...I was abt to give the same reply to you. You need to keep the public class name same as the file name...
Hey Ed Thompson,

Do U say that the lines 1 & 2 give error? Can U let me know the cause?