Jacky Zhang

Greenhorn
+ Follow
since Sep 17, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jacky Zhang

How many of these are checked exceptions?
How is checked exception defined?
please someone help me...
class X { public <X> X(X x) { } }
1st X class name
2nd X generics placeholder/declaration
3rd X constructor name
4th X a type
little x, identifier

Originally posted by deepu verma:

1. In the self test of Chapter 3 Question no 2
Should the answer not be 4 objects, since the line Cardboard c3 = c1.go(c2) would also set the c3 object to null.



no, because c3 is just a reference variable in the stack, no object has ever been created for it to point to in the heap, hence nothing to be GCed.
My study guide says "Static init blocks are executed at class loading time"

Based on C extends B, B extends A and new C() is invoked
my thought is class C should be loaded first before the call within C's constructor to super() which is B's constructor, then before B's constructor runs, B class is loaded, etc.

Thus I would choose CBA... according to my understanding of the class loading time, unless A loads before B, B loads before C, are there any references talks about this?

thanks!
what does s/b stand for?
I really don't understand why option A is wrong.

as normally we can declare:

List<String> list=new ArrayList<String>();

so why when the return type is List<String>,
we can not return a ArrayList<String>?
can anyone help me with this?
my exam day is getting close ...

Originally posted by Barry Gaunt:
System.out refers to an object that is an instance of java.io.PrintStream (see the API for class System). You can synchronize your threads on any object you wish, provided all synchronized threads use the same object.



But how could synchornize on System.out object make line1 and line2 always run in a row? I could imagine something like System.out.print("Z") from another thread could just sneak in between line1 and line2 because after line1 the lock on System.out will be released as System.out.print("X") finishes, this is all because we synchronize on System.out rather than synchronizing on the class, isn't it?

What am I missing?
option F
public void run() { synchronized(System.out) { write(); } }

I don't understand how can you just synchronize on System.out to make the write method always print XY together

public void write() {
System.out.print("X"); //line 1
System.out.print("Y"); //line 2
}

result: cbaa1b1c1

it this correct? thanks in advance


EDIT by mw: Added Code Tags to original poster's indentation.
[ September 18, 2006: Message edited by: marc weber ]
Given a method declared as:
public static <E extends Number> List<E> process(List<E> nums)

A programmer wants to use this method like this:
// INSERT DECLARATIONS HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Integer,
which meets the return collection type <Integer>
and the generic declaration <Integer extend Number>.
ArrayList<Integer> should be campatible with List<Integer>
so this is a correct answer.


B. ArrayList<Integer> input = null;
List<Integer> output = null;

my comments: same reasoning as A, this is a correct answer.


C. ArrayList<Integer> input = null;
List<Number> output = null;

my comments: E replaced by Integer,
List<Number> violates the return collection type which should be
List<Integer>

D. List<Number> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Number,
ArrayList<Integer> violates the return collection type which should
be List<Number>


E. List<Number> input = null;
List<Number> output = null;

my comments: E replaced by Number,
which meets the return collection type List<Number>
and the generic declaration <Number extends Number>.
so this is a correct answer.


F. List<Integer> input = null;
List<Integer> output = null;

my comments: E replaced by Integer,
which meets the return collection type List<Integer>
and the generic declaration <Integer extends number>.
so this is a correct answer.

so my answer would be: ABEF

is it correct?
can we just take it as it is now and what would the answer be?
I ll post up an errata applied edition too.
Given a method declared as:
public static <E extends Number> List<? super E> process(List<E> nums)

A programmer wants to use this method like this:
// INSERT DECLARATIONS HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Integer and ? replaced by Integer,
which meets the return collection type bound <Integer super Integer>
and the generic declaration <Integer extend Number>.
ArrayList<Integer> should be campatible with List<Integer>
so this is a correct answer.


B. ArrayList<Integer> input = null;
List<Integer> output = null;

my comments: same reasoning as A, this is a correct answer.


C. ArrayList<Integer> input = null;
List<Number> output = null;

my comments: E replaced by Integer and ? replaced by Number,
which meets the return collection type bound <Number super Integer>
and the generic declaration <Integer extends Number>.
so this is a correct answer.

D. List<Number> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Number and ? replaced by Integer,
which violates because Integer is not a super of Number.


E. List<Number> input = null;
List<Number> output = null;

my comments: E replaced by Number and ? replaced by Number,
which meets the return collection type bound <Number super Number>
and the generic declaration <Number extends Number>.
so this is a correct answer.


F. List<Integer> input = null;
List<Integer> output = null;

my comments: E replaced by Integer and ? replaced by Integer,
which meets the return collection type bound <Integer super Integer>
and the generic declaration <Integer extends Number>.
so this is a correct answer.

So my answer would be: ABCEF.

Is this correct?
[ September 18, 2006: Message edited by: Jacky Zhang ]
2. HashSet

Don't know about BitSet as far as SCJP 5 is concerned.