class X2 {      
public X2 x;

Loading

Practice Garbage Collections –

class X2 {      
public X2 x;
public static void main(String [] args) {
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
doComplexStuff();
}
}

after line 11 runs, how many objects are eligible for garbage collection?

What will be the output of the program?


			  		

Loading

Practice Declarations and Access Control –

What will be the output of the program?

public class X {     
public static void main(String [] args) {
String names [] = new String[5];
for (int x=0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}

and the command line invocation is

java X a b

What will be the output of the program ?


			  		

Loading

Practice Flow Control –

What will be the output of the program ?

public class CommandArgsTwo {     
public static void main(String [] argh) {
int x;
x = argh.length;
for (int y = 1; y <= x; y++) {
System.out.print(" " + argh[y]);
}
}
}

and the command-line invocation is

java CommandArgsTwo 1 2 3

What will be the output of the program ?


			  		

Loading

Practice Flow Control –

What will be the output of the program ?

public class Test {     
public static void main(String [] args) {
signed int x = 10;
for (int y=0; y<5; y++, x--)
System.out.print(x + ", ");
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class TestDogs {     
public static void main(String [] args) {
Dog [][] theDogs = new Dog[3][];
System.out.println(theDogs[2][0].toString());
}
}
class Dog {
}

 

public class F0091 {
public v

Loading

Practice Flow Control –

public class F0091 {
public void main( String[] args ) {
System.out.println( "Hello" + args[0] );
}
}

What will be the output of the program, if this code is executed with the command line:

java F0091 world

What will be the output of the program?


			  		

Loading

Practice Language Fundamentals –

What will be the output of the program?

public class CommandArgsThree {     
public static void main(String [] args) {
String [][] argCopy = new String[2][2];
int x;
argCopy[0] = args;
x = argCopy[0].length;
for (int y = 0; y < x; y++) {
System.out.print(" " + argCopy[0][y]);
}
}
}

and the command-line invocation is

java CommandArgsThree 1 2 3

Which of the following are Java reserved words?

  1. run

Loading

Practice Language Fundamentals –

Which of the following are Java reserved words?

  1. run
  2. import
  3. default
  4. implement

Which interface does java.util.Hashtable impleme

Loading

Practice Language Fundamentals –

Which interface does java.util.Hashtable implement?

You need to store elements in a collection that guarantees that no

Loading

Practice Objects and Collections –

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?

Which collection class allows you to grow or shrink its size and pr

Loading

Practice Objects and Collections –

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

/* Missing statements ? */ 
pub

Loading

Practice Operators and Assignments –

/* Missing statements ? */ 
public class NewTreeSet extends java.util.TreeSet {
public static void main(String [] args) {
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear() {
TreeMap m = new TreeMap();
m.clear();
}
}

which two statements, added independently at beginning of the program, allow the code to compile?

  1. No statement is required
  2. import java.util.*;

     

  3. import.java.util.Tree*;

     

  4. import java.util.TreeSet;

     

  5. import java.util.TreeMap;