Monday, 31 August 2009

Java Certification Question 0081

How does the set collection deal with duplicate elements?

1) An exception is thrown if you attempt to add an element with a duplicate value
2) The add method returns false if you attempt to add an element with a duplicate value
3) A set may contain elements that return duplicate values from a call to the equals method
4) Duplicate values will cause an error at compile time


Answer)

2) The add method returns false if you attempt to add an element with a duplicate value

I find it a surprise that you do not get an exception.


Sunday, 30 August 2009

Java Certification Question 0080

Which most closely matches a description of a Java Map?

1) A vector of arrays for a 2D geographic representation
2) A class for containing unique array elements
3) A class for containing unique vector elements
4) An interface that ensures that implementing classes cannot contain duplicate keys



Answer)

4) An interface that ensures that implementing classes cannot contain duplicates

Saturday, 29 August 2009

Java Certification Question 0079

When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class. Is this statement

1) true
2) false




Answer)

2) false

You can re-use the same instance of the GridBagConstraints when added successive components.

Friday, 28 August 2009

Java Certification Question 0078

What will happen when you attempt to compile and run the following code?

public class Bground extends Thread{

public static void main(String argv[]){
Bground b = new Bground();
b.run();
}

public void start(){
for (int i = 0; i <10; i++)
System.out.println("Value of i = " + i);
}
}
}

1) A compile time error indicating that no run method is defined for the Thread class
2) A run time error indicating that no run method is defined for the Thread class
3) Clean compile and at run time the values 0 to 9 are printed out
4) Clean compile but no output at runtime



Answer)

4) Clean compile but no output at runtime


This is a bit of a sneaky one as I have swapped around the names of the methods you need to define and call when running a thread. If the for loop were defined in a method called

public void run()

and the call in the main method had been to b.start()

The list of values from 0 to 9 would have been output.

Thursday, 27 August 2009

Java Certification Question 0077

Which statements are correct about the anchor field?

1) It is a field of the GridBagLayout manager for controlling component placement
2) It is a field of the GridBagConstraints class for controlling component placement
3) A valid setting for the anchor field is GridBagConstraints.NORTH
4) The anchor field controls the height of components added to a container


Answer)

2) It is a field of the GridBagConstraints class for controlling component placement
3) A valid settting for the anchor field is GridBagconstraints.NORTH