Java
If the Java class TryMe.class is run using the following command: c:> java TryMe one two three What would be the contents of args[1] in the main program.
"two"
The Java Virtual Machine runs code contained in --?-- files.
.class
What is the extension of a file produced from source code by the Java compiler?
.class
In the Java programming language, all source code is first written in plain text files ending with what extension?
.java
If the Java class TryMe.class is run using the following command: c:> java TryMe 1 2 3 What would be output of the following statements in the main method:
123
Characters, by default, are represented in Java using
16-bit Unicode
The largest possible signed positive integer(int) in Java is
2^31 - 1
If the Java class TryMe.class is run using the following command: c:> java TryMe one two three What is the length of the array args[] in the main program?
3
If the array myArray is declared as int[][] myArray = {{2,3,4,5},{3,4,5,6},{4,5,6,7}} What is the value of myArray.length?
3
If the array myArray is declared as int[][] myArray = {{2,3},{3,4},{4,5}} How many rows and columns does it have?
3 rows, 2 columns
Consider the following statement int a [ ] [ ] = { {1,2}, {3,4,5,6}, {7,8,9,0} } The length of a is --?-- and the length of a[2] is --?--
3;4
If the array myArray is declared as int[][] myArray = {{2,3},{3,4,5,6},{4,5,6}} What is the value of myArray[1].length
4
If the array myArray is declared as int[][] myArray = {{2,3},{3,4},{4,5}} What is the value of myArray[1][1]?
4
What will the output of this program segment: int p [ ] = {2,4,6,8} System.out.println(p [ 2 ] );
6
What is the output of the following code: public class ArrayTest { public static void main(String[ ] args) { int [ ] numbers = {3,6,9,12,15}; doSomething(numbers,3); for (int k=0; k < numbers.length; k++) System.out.print(numbers [k] + " "); } public static void doSomething ( int [ ] n, int i) { for (int j = 0; j < n.length; j++) n [ j ] += I; }
6 9 12 15 18
A menu listener implements the interface
ActionListener
What is the correct command to compile the program HelloWorld.java?
C:>javac HelloWorld.java
Class RunTimeException extends from class
Class Exception
Variables that should not be changed should be declared using the modifier
Final
If a Java class is declared as public class HelloWorld { then the name of the file it is saved in must be
HelloWorld.java
The statement pet1 = new Cat("tabby") is an example of
Instantiating an Object
A --?-- contains a --?-- which contains a --?--.
JMenuBar; JMenu; JMenuItem
Exceptions in Java are
Objects
Which is the correct way to instantiate a new TextFileInput object?
TextFileInput tfi = new TextFileInput("myFile.txt");
What are the two main components of the Java language?
The Java Virtual Machine (JVM) and the Application ProgrammingInterface (API)
What will be the output of the following program? public class Question24 { public static void main (String [ ] args) { String items [ ] = { "2468", "good bye", "1357"}; for (int i=0; I <= items.length; i++) try{ System.out.println("The answer is: " + Integer.parseInt(items[ i ] ); } catch (NumberFormatException nfe) { System.out.println("Too bad! " + items[ i ] ); } catch (ArrayIndexOutOfBoundsException aob) { System.out.println("Better luck next time."); } catch (Exception e) { System.out.println("Oh no!"); } } }
The answer is: 2468 Too bad! good bye The answer is: 1357 Better luck next time.
What will be the result of the following statement: int i = Integer.parseInt("45");
The variable i will get the integer value 45.
Java is great language.
True
What would be an appropriate Regular Expression to match a telephone number?
\d{3}-\d{3}-\d{4}
Consider the following segment of Java code. What will be the output? String cat = "Cat"; System.out.println(cat.charAt(1)); changeCat(cat); System.out.println(cat.charAt(1)); ----------------------------------- public static void changeCat(String dog) { dog = "Cut"; }
a a
Static variables belong to
a class;
What is printed when the main program run public class A { private int a=0; protected int b=0; public int c=0; public A ( int z) { a=z; b=z+1; System.out.println("a is: " + a + b is: " + b); } } public class B extends A { public B (int q) { super(q); } } Main program: r = 2; A aaa = new A(r); B bbb = new B(r+2);
a is: 2 b is: 3 a is: 4 b is: 5
The Java Application Programming Interface (API) is
a large collection of ready-made software components.
A platform is the hardware or software environment in which a program runs.Most platforms can be described as a combination of the operating system andunderlying hardware. The Java platform diff ers from most other platforms inthat it's
a software-only platform
A method that cannot handle an exception is called
an exception propagator
An object is
an instance of a Class which has specific properties
instance variable belong to
an object
If the class equalStrings.class is run using c:> java equalStrings cat dog cat rat dog Which of the following statements will be true?
args[0].equals(args[2])
Java .class fi les must be run by the
ava Virtual Machine (JVM)
What are the contents of a .class fi le in Java?
bytecodes
What is the correct command to run the class HelloWorld.class?
c:>java HelloWorld
The following declaration is for a node in a simple linked list. Choose the letter of the correct code from the table on the right for each question to complete the declaration. public <13> ListNode { Object data; ListNode<14>; public ListNode (object myData) { data = <15>; next = null; }
class, next, myData
The variable b is accessible to public class A { private int a=0; protected int b=0; public int c=0; public A ( int z) { a=z; b=z+1; System.out.println("a is: " + a + b is: " + b); } } public class B extends A { public B (int q) { super(q); } } Main program: r = 2; A aaa = new A(r); B bbb = new B(r+2);
classes A and B
The methods A and B are called public class A { private int a=0; protected int b=0; public int c=0; public A ( int z) { a=z; b=z+1; System.out.println("a is: " + a + b is: " + b); } } public class B extends A { public B (int q) { super(q); } } Main program: r = 2; A aaa = new A(r); B bbb = new B(r+2);
constructors
The purpose of a BufferedReader object is to o
deliver one line of the input file at a time
If the array myArray is declared as int[][] myArray = new int[3][4]; Which of the following loops will set all the cells of the array equal to 10? for (int i=0; i<myArray.length(); i++) for (int j=0; j<myArray[i].length()) myArray[i][j] = 10; for (int i=0; i<myArray.length; i++) for (int j=0; j<myArray[i].length) myArray[i][j] = 10; for (int i=0; i<myArray[i].length; i++) for (int j=0; j<myArray[j].length) myArray[i][j] = 10; for (int i=0; i<myArray.length; i++) for (int j=0; j<myArray.length) myArray[i][j] = 10;
for (int i=0; i<myArray[i].length; i++) for (int j=0; j<myArray[j].length) myArray[i][j] = 10;
A process that is in the RUN state
has control of the CPU
A hash map may be implemented using a
indexed array
If the Java class TryMe.class is run using the following command: c:> java TryMe one 2 three Which of the following statements will cause an error?
int i = Integer.parseInt(args[0]);
A process that is in the READY state
is waiting for a turn on the CPU
Hash maps and Tree maps contain a sequence of
key/value pairs
What is the name of the method that is run fi rst when a Java application islaunched?
main
A recursive definition of an array being in sorted order is: If the first two elements are in order the rest of the array is sorted, then the entire array is sorted. Select the missing parts of the following algorithm to complete the code. public static boolean isSorted (int myArray [ ], int i) { if ( i == myArray.length-1) return true; if(myArray [ i ] < <34>) return isSorted(myArray, <35>); else return false; }
myArray[ i+1 ] i+1
The following code is intended to add a new node to the beginning of a linked list (with dummy head node), declared as follows. For each question choose the best answer to complete the code. private ListNode first; private ListNode last; private int length; public prepend (Object myData) { ListNode n = new ListNode(<16>); n.next = <17>; first.next = n; length++; if(last == first) <18> = n; } //prepend
myData first.next last
What do GUI's do while they are waiting for an action event?
nothing
If the Java class TryMe.class is run using the following command: c:> java TryMe one two three What would be the output of the following statement in the main method:
onetwothree
If the Java class TryMe.class is run using the following command: c:> java TryMe one two three What would be the output of the following statement in the main method: for (int i=0; i<args.length;
owr
Assertions are used during --?-- and exceptions are used during --?--.
program development; program execution for users
What is the correct signature of the main method?
public static void main(String[] args)
Which of the following methods is contained in the class TextFileInput? readLine() charAt() parseShort() new TextFileInput(String s)
readLine()
A tree map may be implemented using a
red-black tree
In Java, object parameters are passed by
reference
In Model/View/Controller the controller is
responsible for updating the data
Which of the following is not a Java Development Tool? javac - the Java compiler javadoc - the Java Documentation producer java - the Java Launcher the JVM
the JVM
In Model/View/Controller, the model is
the data to be displayed
Menu handlers can pass a reference to their own GUI by using the --?—operator.
this
Suppose in the following program segment, x is supposed to be less than 5. Which of the following is the correct code for <statement A> so that an exception is thrown if that is not the case: if (! x<5) <statement A>
throw new IllegalArgumentException("x must be < 5");
If you want items to come out in sorted order it's best to use a
tree map
In Java, primitives are passed by
value
In Java, primitive parameters are passed by --?-- and object parameters are passed by --?--.
value; reference