(100 total points)

Ask if you have a question!!
SSN______-____-________



Directions: Give brief but precise answers to the following questions.



do loop - do { statement(s) } while ( booleanExpression );

while loop - while ( booleanExpression ) { statement(s) }

for loop - for ( initStatement ; testExpression ; iterationExpression ) { statement(s) };



int[] values = new int[10];



for (int i = 0; i < 10; ++i) { values[i] = i + 1; }



Label[] labels = new Label[2];

labels[0] = new Label("one");

labels[1] = new Label("two");



Java arrays with object elements may contain elements of any of the derived classes of the declared array element type. Normally, arrays are homogeneous and may have all elements of the same declared type.



A selection sort selects the largest (or smallest) element from the remained unsorted portion of the list, placing it in its proper position via an exchange with the element currently in the position. An insertion sort inserts the next unsorted element into the already sorted portion of the list by moving sorted elements over one from the right until the correct position is found.









They are dynamic (their size can be modified at any time), there is only one choice for the element type (always contain Object type), and comes with an extensive suite of powerful methods for manipulating the underlying array and its elements.



Once a String instance has been created, it cannot be changed. The string reference variable can only be assigned a new string.



if (first.compareTo(second) < 1) { compares = "less than"; }

else if (first.compareTo(second) == 0) { compares = "equal to"; }

else { compares = "greater than"; }



System.out.println(message.length);



FileOutputStream fos = new FileOutputStream("file.out");

PrintStream ps = new PrintStream(fos);



try {

ps.print(name.length()); ps.print(","); ps.print(name); ps.print(",");

ps.print(age); ps.print(",")

ps.print(married); ps.println();

}

catch (IOException ioe) {

System.err.println(ioe);

}



The throws clause says that the method which contains the clause may throw that exception and, if it does, the error will not be handled and should be passed to the block containing the method call. This passing of the error up the enclosing blocks will occur until a catch handler is found for that exception. If no handler is ever found, the Java run-time environment will eventually catch it.



The throw statement causes an exception to occur; the throws clause says that execution of the method may cause the exception to occur.



The header method writes a leading number which tells how many records follow.



The Read/Write I/O reads/writes binary data from/to the file; the Oread/OWrite I/O reads/writes an objects data from/to the file in accordance with the readFrom and writeTo methods; and the TRead/TWrite reads/writes "ASCII-formatted" data converted to/from binary data.



Applets normally are not allowed access to the client's file system, only the host's file system, whereas windows applications normally are allowed access to the local file system within what local permissions allow.



import java.awt.*;

public class DialogHello extends Frame {

public DialogHello() {

Dialog d = new Dialog(this); d.add(new Label("Hello, Dialog!"));

d.setSize(100, 50); d.show();

}

public static void main(String[] args) { Frame f = new DialogHello(); f.show(); }

}



The File class contains a number of useful methods for finding information about files.



Finally clauses are generally used for cleanup purposes since statements in the try block following the one which caused the exception are never executed.