Java Language Assessment
Instructions:
Answer the following questions without referencing any Java programs or reference materials. If you do not know the answer to a question, leave it blank.
This assessment serves a dual purpose. First, it helps us to gauge the level of your language experience at the onset of the ObjectSpace interview process. Secondly, it alludes to our commitment to identify people that are best qualified for the challenging and exciting positions that are available at ObjectSpace. You are strongly encouraged to complete this assessment without any assistance in order to help both you and us get an accurate picture of your basic skills.
Once you have completed the test, send the test along with your answers to:
ObjectSpace, Inc.
Recruiting
14881 Quorum Drive, Suite 600
Dallas, TX 75240
Fax: (972) 715-9081
hr@objectspace.com
Candidate Name: Hasan Timucin Ozdemir _
Candidate Phone Number: (315) 428 8668 _
Date: Apr. 20th, 1999 _
Recruiter Name: Lori Davis _
Multiple Choice
For each of the following questions, select the one answer which best applies.
1. (1 point) What will be the output of running the following code?
public class A {
String name = "Bob";
A(){ String name = "Frank"; }
String getName() { return name; }
public static void main( String[] args ) {
System.out.println ( new A().getName() );
}
}
2. (1 point) Is the following legal?
interface Harpo { double vision(); }
interface Foreigner { double vision(); }
class Combined implements Harpo, Foreigner {
public double vision() { return 42.0; }
}
3. (1 point) What must be true for a class to be serializable?
4. (1 point) What type must you use in place of "???" for the following example to work?
interface Harpo { float vision(); }
interface Foreigner { double vision(); }
class Combined implements Harpo, Foreigner {
public ??? vision() { return 42.0; }
}
5. (1 point ) Which of the following modifiers must be used in place of "???" to prohibit access to "field" from outside of Bar?
class Bar {
??? int field;
}
6. (1 point) What happens if an unchecked exception is thrown from a finalize () method?
7. (1 point) What may be true of class Timer for the following to work:
Timer timer = new Timer();
Thread thread = new Thread( timer );
thread.start();
8. (1 point) What method(s) are declared by the Serializable interface?
9. (1 point) What does the following code output?
Vector v = new Vector();
v.addElement( 10 );
v.addElement( 20 );
System.out.println( v );
10. (1 point) We want to iterate through a Vector, v, that contains multiple objects. Which of the following will do this?
a) Enumeration e = v.getElements();
while( e.hasMoreElements() )
System.out.println( v.nextElement() );
b) Enumeration e = v.elements();
while( e < v.size() )
System.out.println( v.nextElement() );
(*) c) Enumeration e = v.elements();
while( e.hasMoreElements() )
System.out.println( e.nextElement() );
d) Enumeration e = new Enumeration( v );
while( e.hasMoreElements() )
System.out.println( e.nextElement() );
e) none of the above
11. (1 point) Which container class is not included in the 1.1.1 JDK?
12. (1 point) Considering the following code, what happens when B is run?
class A {
int a;
A() { init(); }
void init() { System.out.print( "A" ); }
}
class B extends A {
int b;
B() { init(); }
void init() { System.out.print("B"); }
public static void main( String[] args ) { new B(); }
}
13. (1 point) What has to be true for an inner class to reference a local variable?
14. (1 point) Consider the following code:
import java.util.*;
class B {
static Vector v = new Vector();
//other stuff here
public void finalize() {
v.addElement( this );
}
}
The intent of this code is to prevent any B from ever being Garbage Collected. Comment on this.
The following code is used for the next two questions:
Frame frame = new Frame();
GridBagLayout layout = new GridBagLayout();
frame.setLayout( layout );
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridwidth = 2;
Button button = new Button( "Hello" );
frame.add( button );
frame.show();
15. (1 point) In order to have the constraints apply to the button, what should appear in the blank line?
16. (1 point) Assume that the grid width is to be 2. What code needs to be added to make the button stretch across the entire screen?
All That Apply
For each of the following questions, select all the answers which are true.
17. (2 points) Which of the following are part of the Java threading model?
18. (2 points) Considering the following, which of the following expressions evaluate to true?
String s1 = "string";
String s2 = s1;
String s3 = new String( s1 );
Written
For each of the following questions, provide a written answer. Make sure to answer each part of a question. Be careful not to confuse "how" answers with "why" answers.
19. (2 points) Is an object's finalize() method guaranteed to be called? Why or why not?
Nope. GC determines when to collect garbage.20. (2 points) What are the methods used for Applet lifecycle control?
init(), start(), stop(), and destroy().21. (2 points)Using the following code
class Foo {
public void tryIt( int j ){
try {
try {
int i = 9;
int k = i/j; // throws ArithmeticException, a subclass of RuntimeException
throw new IOException( "Uh OH!" );
}
catch( IOException exception ) {
System.out.println( "Hi-ho, hi-ho, I just threw IO! " );
}
finally {
System.out.println( "Whew! Finally!" );
}
}
catch( ArithmeticException exception ) {
System.out.println( "Divide By Zero! " );
}
}
}
What would be the output of:
Foo foo = new Foo();
foo.tryIt( 0 );
foo.tryIt( 1 );
22. (2 points) Write an example of using an inner class. Why are inner classes useful? Where are they commonly used?
public class A extends JTable { public A() {} .... class Student { String name; Student(String name) { this.name; } } }Prevents name clashing and extensive number of files if the required process and object is local. It gives narrower scope than package and can be put into the definition of class where it is being used. As above, if the Student object is only needed and used by class A, then it is unncessary to define this object in the same package with A since none of the objects in the package is gonna use it anyway. It can also give extra data abstraction to the peer classes in the same package.