Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Felix Tang

Greenhorn
+ Follow
since Aug 15, 2006
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 Felix Tang

Ok, I'm a lot worse than 99% of you guys, but I'm really happy I passed this on 2nd attempt. Got 68% The questions were so hard at the beginning but I got through! So happy!
15 years ago

Originally posted by Jon Lee:
BTW, Felix. Where can I get this Felix diagnostic exam?? Is it free?



This is from the Whizlab package. You can check from the FAQ. I downloaded the trial and it gives you about 15 Qs with explanations + free diagnostic test but no solutions.

thanks for the clarifications
This is Q58 of the diagnostic exam:

class ThreadDemo {

private int count = 1;

public synchronized void doSomething()
{
for (int i = 0; i < 10; i++)
System.out.println(count++);
}

public static void main(String[] args)
{
ThreadDemo demo = new ThreadDemo();
Thread a1 = new A(demo);
Thread a2 = new A(demo);
a1.start();
a2.start();
}
}

class A extends Thread
{
ThreadDemo demo;
public A(ThreadDemo td)
{
demo = td;
}

public void run()
{
demo.doSomething();
}
}

A. It will print 0 to 19 sequentially.
B. It will print 1 to 20 sequentially.
C. It will print 1 to 20, but order cannot be determined.
D. It will print 0 to 19, but order cannot be determined.
E. The code will not compile.

If I'm not wrong, the answer should be B. What I want to ask is: wouldn't the synchronized method doSomething() give the same result if the method is NOT synchronized? (since both threads took the same reference of demo and share the instance for variable count)
Q37 of the diagnostic test:

You want to execute a class named My.class in the package whiz.utilities.myapp. The path to that directory is

/java/MyPackages/whiz/utilities/myapp

Which command would you use to run the class?

A. java -classpath . /java/MyPackages/whiz/utilities/myapp My
B. java -classpath /java/MyPackages whiz.utilities.myapp.My
C. java -classpath . java.MyPackages.whiz.utilities.myapp.My
D. java -classpath ./java/MyPackages/whiz/utilities/myapp/My

Am I right to say the answer is B? You can't have a dot without the separator colon( right after it.
From Q55 of the diagnostic exam:


class TestThread extends Thread
{

private int i;
public void run()
{
i++;
}

public static void main(String[] args)
{
TestThread a = new TestThread();
a.run();
System.out.print(a.i);
a.start();
System.out.print(a.i);
}
}

Should the answer be "prints 11" or "prints 11 or 12"?
Hi, this is a question from one of the MasterExams from the K & B CD-ROM.

import java.util.*;
public class Mangler
{
public static <K,V> Map <V,K> mangle(Map <K,V> in){
Map <V,K> out = new HashMap <V,K>();
for (Map.entry<K,V> entry: in.entrySet())
out.put(entry.getValue(), entry.getKey());
return out;
}

public static void main(String[] args)
{
Map m1 = new HashMap();
m1.put("a", 1);
m1.put("b", 2);
Map m2 = mangle(m1);
System.out.println(m2.get("a") + "" + m2.get(2));
}
}

The answer is "null b". I read the explanation but I still don't understand why. And why does entry.getValue() belong to type <V> and entry.getKey() belong to type <K>?

Any help would be appreciated