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

Gong James

Ranch Hand
+ Follow
since Oct 15, 2001
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 Gong James

To James Thomson:
StringBuffer sb1 = new StringBuffer("test");
StringBuffer sb2 = new StringBuffer("test");
System.out.println(sb1.equals(sb2));
will print the false not true.

To abdul khayyum:
I think you are right .Thank you.
The method equals of String override that method of in Object ,so it is design to compare to see whether the value of the two string have the same value.But in the StringBuffer there's not the equals method ,that means if use the method in Object,which only compare to see if the two object are the same.
I try my conclusion above ,but according the StringBuffer,it is not the true,so I am confused,
could sb tell me that ,in what condition the equals is only to compare the value of the objec ,but not to compare for a result whether the two object are the same object.
I think :
the method's calling is according to the type of the instance ,so when invoke the speak,it will call the speak method in class Test1 ,it will not to call the method in Object.
public class Test1
{
public static void main(String arg[])
{
Object bb=new Test1();
bb.speak();
}
void speak()
{
System.out.print("I am OK!");
}
}
when I comile the code the following is print out.
I think when the speak is invoke ,it only execute the speak of the instance method ,and the instance method speak has been defined,it should not give a copile error.
But ........
//---------compile error------------//
Test1.java:6: ������������
���������� speak ()
�������� in java.lang.Objec
bb.speak();
^
1 ������
//------------end-----------------//
Can you give me a explain about the above.
public class test
{
public static void main(String arg[])
{
Math m=new Math();
System.out.println("m.round="+m.round(100.00));
}
}

when compile the code ,the code give me a compile error:there isn't a construcor in class Math,but I look up in the jdk-doc,the Math is subclass of the class Object,the Object have a no-arg constructor : public Object()
,which mean that when instance the Math class,it will invoke the super class(Class)'s no-arg constructor : public Object().
If i am right about the question,how can I explain this.
in the synchronized block has the code:"thread.sleep(50000);"
whether the thread will release the lock ?
public class AllFinals
{
{
final Vector v;
v=new Vector();
}
public AllFinals()
{
}
public void someMethod()
{
System.out.println(v.isEmpty());
}
}
An attempt to compile and call the someMethod of the above class at runtime will cause

A) A compilation error : v is not initialized in all constructors
B) A compilation error : v is not an instance variable
C) "true" is printed on the console
D) "false" is printed on the console
The given ans is;B.which had been proved right.
But i think the block
{
final Vector v;
v=new Vector();
}
is execute once the class AllFinals is loaded,which is seems like the memebre field,as a result,the compile give me error as the ANS B said,but when the block code is execute?
//-------------------------the code---------------------//
interface AnInterface
{
public void methodOne() throws Exception;
}

class AnInterfaceImpl implements AnInterface
{
public void methodOne()
{
System.out.println("I will never throw an exception");
}
}
public class ATest
{
public static void main(String args[])
{
AnInterface ai = new AnInterfaceImpl();
ai.methodOne();
}
}
Attempting to compile and run the above code
A) Will cause a compile time error. (Line 5 : Exception must be caught or thrown by main(String))
B) Will cause a compile time error for Class AnInterfaceImpl. The method methodOne() be declared with "throws Exception".
C) Will cause no compile time error and print "I will never throw and Exception the screen".
D) Will Cause a run time error .
the given ans is :A;
when I change the main method declarationof class Atest to : public static void main(String args[]) throws Exception
everything is ok!
But I think in the main method ,the instance ai only invoke the method methodOne which override superclass's methodOne,and in it��s declareation ,it doesn��t throws any Exception ,as a result ,the main needn��t throws the Exception.
but ......the facts wins me!
could you give me the reason!


//Read the code following and ans the question.

A) will cause a compile time error.(Exception must be caught or thrown by main(String)).
B)will cause a compile time error for Class InInterfaceImpl.The method methodOne() be declared with throws Exception".
C)will cause no cmpile time error and print"I will never throw and Exception the screen".
D)Will cause a run time error.
Given ans:A.

In this case ,we but a instance of AnInterfaceImp(suber-class),the reference type is AnInterface(super-class),I think we when we call the method ,it prefer the instance type,while the variable it prefer the reference type,as a result above ,when we call the ai.methodOne() in main(String arg[]),it will not invoke the methodOne of supper-class.but when I compile ,it give me the error that the main(String arg[]) shoud caught or throws a throws execption statement.
[This message has been edited by Gong James (edited November 05, 2001).]

(Marilyn added code tags)
[This message has been edited by Marilyn deQueiroz (edited November 06, 2001).]
Question 91.
Read the following code excerpt carefully. //Contents of file A.java
Which of the following are true
1.A.java cannot be compiled. Duplicate defination of inner class B.
2.A.java compiles without any error. An attempt to run C as an application will cause runtime linkage error. Duplicate definations of inner class B are found
3.Only one class file corresponding to the inner class B is created in the file system.
4.Two class files corresponding to both inner classes (B) is created in the file system.
5.The classes compile cleanly and on running C as an application causes "I am in the arg constructor" to be printed on the console

the given ans is;4.5.
I dont know why there there are two class file(A$1$B.class ,A$2$B.class)of class B is created when i compiled the code.

(Marilyn added code tags)
[This message has been edited by Marilyn deQueiroz (edited November 03, 2001).]
Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.
a)true.
B)false

the given as:B.

I think when the system run the gc,it will certain collect the object that unreachable(unmarked) object.
But we are not sure whether the system will run the gc,or when the system will run gc.

As is well know that Vector is serializable ,but when i look up the jdk-doc ,I can't find the key-word such as "implements serializable "or"implements exserializable ".

Can you give me a explaination about it ,thank you very much ,I am beginner!!
Question 66.
Class fields with which of the following modifiers will not be serialized

1)private
2)static
3)transient
4)protected
the given ans:2.3.

Pls tell me the parallel comment about the serialized concern the Question.
Of course you are right,but you mistaked my meaning.
you know java allow you to change the layoutmanager,when the layoutmanager is changed ,the container will layout the component with it's rule.

Concern this case ,i changed the layoutmanager to flowlayout manager,but the button doesn't appear as my plan.
Why?or What's the rule when layout manager is changed from border layout to flow layout ?
20 years ago
Of course you are right,but you mistaked my meaning.
you know java allow you to change the layoutmanager,when the layoutmanager is changed ,the container will layout the component with it's rule.

Concern this case ,i changed the layoutmanager to flowlayout manager,but the button doesn't appear as my plan.
Why?or What's the rule when layout manager is changed from border layout to flow layout ?