Section 1

Preview this deck

What will the following java code produce as output? int number; number = 1; while ( number < 6 ) { System.out.print(number); number = number + 1; } System.out.print("Done!");

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (203)

Section 1

(50 cards)

What will the following java code produce as output? int number; number = 1; while ( number < 6 ) { System.out.print(number); number = number + 1; } System.out.print("Done!");

Front

b. 12345Done!

Back

True or False: A variable has a value that can not be changed by the program

Front

False

Back

What output will the following code produce: int counter; counter = 5; counter += 1; System.out.println(counter);

Front

b. 6

Back

True or False: The while loop is used when a known, finite number of loop iterations is required.

Front

False

Back

True or False: A name for a constant value in java is called a literal.

Front

True

Back

True or False: The do-while loop repeats a set of code at least once before the condition is tested.

Front

True

Back

Consider the following subroutine: static void showFrame(int frameNum) Now study the following two statements 1) for (int i = 1; i <= 30; i++) showFrame(i); 2) for (int play = 0; play < 10; play++) { for (int i = 1; i < 30; i++) showFrame(i); } Select the best description of statements 1) and 2):

Front

b. 1) displays 30 animation frames in order; 2) replays the animation 10 times

Back

True or False: The break loop when encountered will cause processing to skip to the beginning of the loop?

Front

False

Back

True or False: A variable of type boolean in java can have precisely two literals.

Front

True

Back

The operation ++ in Java means:

Front

a. That the value of 1 is added to the variable

Back

True or False: The fetch and execute cycles always alternate?

Front

True

Back

A variable of type 'float' is represented in ___ bytes:

Front

b. 4 bytes (32 bits)

Back

What is the following java code structure known as: for (i=0; i<10; i++) { for (j=0; j<10; j++) { // do something } }

Front

a. Nested loop

Back

Which of the following is an object type?

Front

d. String

Back

True or False: The word "public" when placed in front of a method declaration in java means that the routine can only be called from within the local class

Front

False

Back

An "animation" consists of a sequence of images shown rapidly one after the other on the computer screen. Each image in the animation is called a "frame." Suppose that you have a subroutine static void showFrame(int frameNum) that displays one frame in an animation. That is, showFrame(1) displays the first frame, showFrame(2) displays the second frame, and so on. Suppose that there are a total of thirty different frames. How many frames will the following code display?: for (int play = 0; play < 10; play++) { for (int i = 1; i < =30; i++) showFrame(i); }

Front

a. 30 frames repeated 10 times

Back

What output will the following code produce: int x, y; boolean sameSign; x=1; y=1; sameSign = ((x>0)==(y>0)); System.out.println(sameSign);

Front

a. true

Back

True or False: The for loop continues while a condition is true, and it ends when that condition becomes false. Select one:

Front

True

Back

In Java, a variable of type long is ___ bytes in size.

Front

c. 8 bytes (64 bits)

Back

True or False: The while loop repeats a set of code while the condition is false.

Front

False

Back

The rules that determine what is allowed in a program are known as the ____ of the language.

Front

a. syntax

Back

True or False: A for loop can use a list structure such as an enum to iterate the for loop?

Front

True

Back

enum Season { SPRING, SUMMER, FALL, WINTER } ; Season vacation; vacation = Season.SUMMER; System.out.println(Season.SUMMER);

Front

b. Season.SUMMER

Back

What output will the following code produce: int number; number = 1; while ( number < 6) { System.out.print(number); number += 1; }

Front

a. 12345

Back

Suppose that the first line of a subroutine definition is: static void test(int n, double x). Now consider these statements: test(17,42) test(0.17,3.227) Which of those statements is a legal subroutine call?

Front

b. 1

Back

Here is the definition of the Pythagoras function: static double Pythagoras (double x, double y) { // Computes the length of the hypotenuse of a right // triangle, where the sides of the triangle are x and y. return Math.sqrt( xx + yy ); } Now, what is the result of the following statement: totalLength = 17 + Pythagoras (12,5);

Front

c. 30

Back

Which of the following statements about the 'block' statement are true.

Front

a. it groups a sequence of statements into a single statement

Back

A statement with the following format variable1 = ( x>=2) ? x++ : x--; is employing a:

Front

a. conditional operator

Back

True or False: A computer is built to carry out instructions that are written in a simple type of language.

Front

True

Back

A "black box" has an interface and an implementation. Which of the following statements describe interface?

Front

a. The interface of a black box is its connection with the rest of the world, such as the name and parameters of a subroutine

Back

In which of the following examples can a NumberFormatException occur?

Front

a. When an attempt is made to convert a string into a number.

Back

Variables of the type short can have values in the range of:

Front

b. integers in the range -32768 and 32767

Back

A language that generates a syntax error when you try to put a different data type into a variable that it has not be declared for is called a ________ language

Front

a. strongly typed

Back

In java, a variable can only be used in a program if it has first been:

Front

a. declared

Back

True or False: The conditional expression in a while loop can be any expression that evaluates to a logical True or False?

Front

True

Back

True or False: One of the components of a computer is its CPU, which executes programs."

Front

True

Back

True or False: Can a for statement loop indefinitely?

Front

True

Back

True or False: Java programs are NOT compiled.

Front

False

Back

A program contains a switch statement that lets you test the value of an expression and, depending on that value, to jump directly to some location within the switch statement. When compiling the program, when will a Java compiler report an error?

Front

b. If the value of the expression is a float or a double. or b. If the value of the expression is a real number.

Back

What will be the value of "x" if stringFunction is called as follows: String x = stringFunction("mississippi"); static String stringFunction(String str) { String test; int i; test = ""; for (i = str.length() - 1; i >= 0; i--) { test = test + str.charAt(i); } return (test); }

Front

c. ippississim

Back

Subroutines in Java are often referred to as:

Front

d. methods

Back

True or False: A for loop is used when the number of iterations through the loop in known in advance?

Front

True

Back

A memory location that has been given a name is called a:

Front

a. variable

Back

What are formal parameters ?

Front

a. Formal parameters are found in the subroutine definition. The values of the actual parameters are assigned to the formal parameters before the body of the subroutine is executed.

Back

True or False: An asynchronous event is one that occurs at an unpredictable time outside the control of the program that the CPU is running.

Front

True

Back

The size of a variable of type double is:

Front

a. 8 bytes

Back

Which of the following is NOT a primitive data type.

Front

d. String

Back

True or False: An enum (enumerated type) is a example of an object type instead of a primitive type?

Front

True

Back

True or False: The continue statement when used in a loop will cause the flow of process to skip to the end of the loop and begin another iteration of processing?

Front

True

Back

Which statement is most valid regarding the following java code: while ( true ) { System.out.print("loop again"); }

Front

a. it is a infinite loop that will continue to loop forever (until the program is terminated)

Back

Section 2

(50 cards)

True or False: In Java no variable can ever hold an object. It can only hold a reference to an object.

Front

True

Back

Which of the following code in A or B, or both creates an object of the java.util.Date class? A: public class Test { public Test() { new java.util.Date(); } } B: public class Test { public Test() { java.util.Date date = new java.util.Date(); } }

Front

d. Both

Back

True or False: The variables that an object contains are called local variables.

Front

False

Back

In the following code which method is the constructor? public class theDemo { int val1; int val2; public int Demo1() { val1 = 1; } public int Demo2() { val2 = 2; } public theDemo() { val1 =0; val2 =0; } public void showDemo() { System.out.println(val1); } }

Front

c. theDemo()

Back

Examine the following class public class PatientRecord { public String lastname; // Patient's last name public int age; // Patient's age on admission public bool sex; // Indicates if patient is male or female } Initial values of lastname, age and sex instance variables will be:

Front

b. null, 0, false

Back

Suppose a class has public visibility and defines a protected method. Which of the following statements is correct?

Front

d. This method is accessible from within the class itself and from within all classes defined in the same package as the class itself

Back

When the word public or private is added to a variable or subroutine definition these words are referred to as:

Front

a. Access Specifiers

Back

True or False: When a programmer neglects to delete objects that are no longer used it is referred to as a memory leak.

Front

True

Back

True or False: It should be possible to change the programming of a subroutine without affecting its interface or the programs that use the subroutine.

Front

True

Back

A method that is associated with an individual object is called:

Front

c. an instance method

Back

Consider the following code, which output is correct? public class Student { int age; static int age2 = 3; public static void main(String[] args) { Student student1; Student student2; Student student3; student1 = new Student(); student1.age = 10; student2 = student1; student2.age -= 5; student3 = new Student(); System.out.println(student1.age+" "+student2.age); } }

Front

a. 5 5

Back

True or False: Java Packages can contain other packages.

Front

True

Back

What will the output of the following code be: int A=5; int N=3; int D; D = calcValue(A); System.out.println(D); static int calcValue( int N ) { int D; for( D=1; D<5; D++) { N++; } return(N); }

Front

a. 9

Back

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } }

Front

b. s1 and s2 reference to different String objects.

Back

What are formal parameters ?

Front

a. Formal parameters are found in the subroutine definition. The values of the actual parameters are assigned to the formal parameters before the body of the subroutine is executed.

Back

True or False: The variables that an object contains are called local variables.

Front

False

Back

To declare a constant MAX_LENGTH as a member of the class, you write

Front

e. final static double MAX_LENGTH = 99.98;

Back

In the following code what is the getName() method referred to: public class Student { public String name; public int age; public String getName() { return name; } public void setName( String newName ) { name = newName; } }

Front

a. getter method

Back

A method that is associated with an individual object is called:

Front

c. an instance method

Back

The parameters in a subroutine definition are called:

Front

a. formal parameters

Back

True or False: In java, Garbage Collection is the process that reclaims the memory used by objects which are no longer in use.

Front

True

Back

True or False: A function is a subroutine that has a type of void and returns no value.

Front

False

Back

True or False: In Java no variable can ever hold an object. It can only hold a reference to an object.

Front

True

Back

True or False: The following directive is valid within Java: import java.*;

Front

False

Back

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } }

Front

b. s1 and s2 reference to different String objects.

Back

The abbreviation OOP stands for:

Front

Object oriented programming

Back

True or False: In the following code, the object created from class Student is stored in the variable myStudent. Student myStudent; myStudent = new Student();

Front

False

Back

Consider the following statement: crt = new Circuit(); Which statement best describes the object that has been created?

Front

c. The variable crt refers to the object.

Back

What is the output of the following code? import java.util.Date; public class Test { public static void main(String[] args) { Date date1 = new Date(); Date date2 = new Date(); System.out.print((date1 == date2) + " " + (date1.getClass() == date2.getClass())); } }

Front

c. false true

Back

True or False: local variables are automatically initialized with a default variable where member variables are not.

Front

False

Back

In the following code what is the getName() method referred to: public class Student { public String name; public int age; public String getName() { return name; } public void setName( String newName ) { name = newName; } }

Front

a. getter method

Back

In the following code what is the setName() method referred to: public class Student { public String name; public int age; public String getName() { return name; } public void setName( String newName ) { name = newName; } }

Front

a. setter method

Back

True or False: It is legal to have one subroutine physically nested inside another.

Front

False

Back

True or False: The area of memory that objects reside in is known as the stack

Front

False

Back

What is the output of the following code? import java.util.Date; public class Test { public static void main(String[] args) { Date date1 = new Date(); Date date2 = new Date(); System.out.print((date1 == date2) + " " + (date1.getClass() == date2.getClass())); } }

Front

c. false true

Back

A: public class Test { public Test() { new java.util.Date(); } } B: public class Test { public Test() { java.util.Date date = new java.util.Date(); } }

Front

d. Both

Back

What will the output of the following code be: int N=5; int D=4; int A=0; calcValue( N ) System.out.println(N); static void calcValue( int N ) { int D; for (D=0; D<5; D++) { N++; } }

Front

a. 5

Back

Consider the following code. What will the output of the code be? import java.io.*; public class myStuff { static int num1 = 0; int num2; public static void main(String a[]) throws Exception { myStuff s1 = new myStuff(); s1.num1 = 5; s1.num2 = 10; myStuff s2 = new myStuff(); s2.num1 = 15; s2.num2 = 15; System.out.println("s1 num1="+s1.num1+" num2="+s1.num2+" s2 num1="+s2.num1+" num2="+s2.num2); } }

Front

a. s1 num1=15 num2=10 s2 num1=15 num2=15

Back

True or False: When a programmer neglects to delete objects that are no longer used it is referred to as a memory leak.

Front

True

Back

True or False: The area of memory that objects reside in is known as the stack.

Front

False

Back

In the following code what is the setName() method referred to: public class Student { public String name; public int age; public String getName() { return name; } public void setName( String newName ) { name = newName; } }

Front

a. setter method

Back

Consider the following code, which output is correct? public class Student { int age; static int age2 = 3; public static void main(String[] args) { Student student1; Student student2; Student student3; student1 = new Student(); student1.age = 10; student2 = student1; student2.age -= 5; student3 = new Student(); System.out.println(student1.age+" "+student2.age); } }

Front

a. 5 5

Back

True or False: In the following code, the object created from class Student is stored in the variable myStudent. Student myStudent; myStudent = new Student();

Front

False

Back

In the following code, what is the newStudent method called: public class newStudent { public String name; public int age; public newStudent() { age=5; name = "Jim Jones"; } }

Front

b. constructor

Back

True or False: In java, Garbage Collection is the process that reclaims the memory used by objects which are no longer in use.

Front

True

Back

The abbreviation OOP stands for:

Front

c. Object oriented programming

Back

In the following code, what is the newStudent method called: public class newStudent { public String name; public int age; public newStudent() { age=5; name = "Jim Jones"; } }

Front

b. constructor

Back

To declare a constant MAX_LENGTH as a member of the class, you write

Front

e. final static double MAX_LENGTH = 99.98

Back

A class that is NOT abstract is said to be?

Front

a. concrete

Back

True or False: The purpose of the import directive is that it makes it possible to use the full name when using a class.

Front

False

Back

Section 3

(50 cards)

What will this program print out? class Base{ int value = 0; Base(){ addValue(); } void addValue(){ value += 10; } int getValue(){ return value; } } class Derived extends Base{ Derived(){ addValue(); } void addValue(){ value += 20; } } public class Test { public static void main(String[] args){ Base b = new Derived(); System.out.println(b.getValue()); } }

Front

d. 40

Back

Which component cannot be added to a container?

Front

d. None of the above

Back

Show the contents of the array A after the following code has been executed: int[] A; A = new int[7]; A[0] = 1; A[1] = 1; for (int i = 2; i < 7; i++) { A[i] = A[i-1] + A[i-2]; } a. A[0] = 1 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 5 A[5] = 8 A[6] = 13 b. A[0] = 1 A[1] = 1 A[2] = 2 A[3] = 2 A[4] = 5 A[5] = 8 A[6] = 13 c. A[0] = 1 A[1] = 2 A[2] = 2 A[3] = 3 A[4] = 5 A[5] = 9 A[6] = 13

Front

a. a.

Back

Which statements are false? A dynamic array:

Front

b. Does not allow you to put a value at a given position and get the value that is stored at a given position c. There is an upper limit on the positions that can be used.

Back

Which of the following methods would you use to display graphics that have been changed or added?

Front

a. repaint()

Back

True or False: The import directive makes it possible to refer to a class such as java.awt.Color using its simple name Color.

Front

True

Back

Which of the following class definitions defines a legal abstract class? a. class A { abstract void unfinished() { } } b. class A { abstract void unfinished(); } c. abstract class A { abstract void unfinished(); } d. public class abstract A { abstract void unfinished(); }

Front

c. c

Back

Which method sets the font (Arial, 16-point bold) in component Q?

Front

q.setFont(new Font("Arial", Font.BOLD, 16))

Back

Suppose int[] ages = {1, 20, 30, 40, 50}. What value does java.util.Arrays.binarySearch(ages, 30) return?

Front

e. 2

Back

The handler (e.g., actionPerformed) is a method in ________

Front

a. a listener object

Back

What is the relationship between objects of class Button and ActionEvents? A. When a button is clicked, it generates an event. This event is represented by an object of type ActionEvent. B. This object is passed to the actionPerformed method of any ActionListener that has been registered to listen for action events from the button. C. ActionEvents are part of the mechanism that is used to make some action occur when a button is clicked.

Front

A., B., C.

Back

Study the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test extends A { public static void main(String[] args) { A frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } class A extends JFrame implements ActionListener { JButton jbtCancel = new JButton("Cancel"); JButton jbtok = new JButton("OK"); public A() { getContentPane().setLayout(new FlowLayout()); getContentPane().add(jbtCancel); jbtCancel.addActionListener(this); getContentPane().add(jbtok); jbtok.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtCancel) { System.out.println("Cancel button is clicked"); } if (e.getSource() == jbtok) { System.out.println("OK button is clicked"); } } }

Front

a. The program displays Cancel button on the left of the OK button. b. When you click the OK button the message "OK button is clicked" is displayed. c. When you click the Cancel button the message "Cancel button is clicked" is displayed. d. All of the above Correct

Back

When you return an array from a method, the method returns ...

Front

d. The reference of the array

Back

True or False: While a class can extend only one other class, a class can implement many interfaces?

Front

True

Back

True or False: The static import statement will enable you to use the simple name of members of a class such as java.lang.Math.* (methods and variables):

Front

True

Back

Which of the following statements are true?

Front

b. The keyPressed handler is invoked when a key is pressed. c. The keyReleased handler is invoked when a key is released. d. The keyTyped handler is invoked when a Unicode character is entered.

Back

What is the result of the following code? import javax.swing.*; import javax.swing.border.*; import java.awt.*; public class Test extends JFrame { public Test() { Border border = new TitledBorder("My button"); JButton jbt1 = new JButton("OK"); JButton jbt2 = new JButton("Cancel"); jbt1.setBorder(border); jbt2.setBorder(border); getContentPane().add(jbt1, BorderLayout.NORTH); getContentPane().add(jbt2, BorderLayout.SOUTH); } public static void main(String[] args) { JFrame frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }

Front

a. Two buttons displayed with the same border.

Back

A programmer wishes to perform the following: - create a two-dimensional array of int with 3 rows and 4 columns - store a 17 into each element of the array. Which Java code (A, B, or C) should be used? a. int[][] array2D; array2D = new int[3][4]; for (int row = 0; row < 3; row++) { for (int col = 0; col < 17; col++) array2D[row][col] = 10+7; } b. int[][] array2D; array2D = new int[3][4]; for (int row = 0; row < 3; row++) { for (int col = 0; col < 4; col++) array2D[row][col] = 17; } c. int[][] array2D; array2D = new int[3][4]; for (int row = 1; row < 3; row++) { for (int col = 1; col < 4; col++) array2D[row][col] = 17; }

Front

b. b.

Back

Which interface should be implemented to listen for a button action event?

Front

b. ActionListener

Back

True or False: HTML stands for HyperText Management Language:

Front

False

Back

Consider the following code: import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { Component c = new JButton("OK"); JFrame frame = new JFrame("My Frame"); frame.add(c); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }

Front

a. You cannot add a Swing component directly to a JFrame. Instead, you have to add it to a JFrame's contentPane using frame.getContentPane().add(c).

Back

Consider the following code. What will the output be when a new instance of an myStuff object is created? public class myStuff extends Stuff { String myName = "Steve"; public myStuff() super() ; System.out.println(myName); } } public class Stuff { String myName; public Stuff () myName = "Dave"; } }

Front

a. Steve

Back

To draw a circle with radius 20 centered at (50, 50) for a graphics object obj, use this method:

Front

a. obj.drawOval(30, 30, 40, 40)

Back

True or False: A variable that can hold a reference to an object of class A can also hold a reference to an object belonging to any subclass of A.

Front

True

Back

The most common technique for handling events in Java is to use an:

Front

b. event listener

Back

Object-oriented programming allows you to derive new classes from existing classes. This capability is known as:

Front

d. Inheritance

Back

True or False: The term polymorphism refers to the fact that one class can acquire part or all of the structure and behavior from another class.

Front

False

Back

What layout manager should you use so that every component occupies the same size in the container?

Front

b. GridLayout

Back

______ search is the process of searching an array by looking at each item in turn; while ______ search is a method for searching for a given item in a sorted array.

Front

c. Linear ... binary

Back

Which of the following methods (assuming that the proper parameters are supplied) can be used to draw the shape below? redbox

Front

c. fillRect()

Back

Which of the following statements are correct?

Front

a. char[][][] charArray = new char[2][2][]; c. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

Back

True or False: The flow layout manager simply adds components to a panel in series in the order that they are added.

Front

True

Back

What array processing technique is shown in the following code sample? static void process_technique (int[] A, int itemsInArray, int newItem) { int loc = itemsInArray - 1; while (loc >= 0 && A[loc] > newItem) { A[loc + 1] = A[loc]; loc = loc - 1; } A[loc + 1] = newItem; }

Front

b. Insertion sort

Back

Show the exact output produced by the following code segment. char[][] pic = new char[6][6]; for (int i = 0; i < 6; i++) for (int j = 0; j < 6; j++) { if ( i == j || i == 0 || i == 5 ) pic[i][j] = '*'; else pic[i][j] = '.'; } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) System.out.print(pic[i][j]); System.out.println(); a. ** ....*. ...*.. ..*... .*.... ** b. ** .*.... ..*... ...*.. ....*. ** c. ...... .*.... ..*... ...*.. ....*. ** d. ** ....*. ...*.. ..*... .*.... ...... Sele

Front

b. b.

Back

A GUI is built of components. A component is a visual element in a GUI that belongs to the class javax.swing.JComponent or java.awt.Component. Which of the following is NOT a component

Front

b. JApplet

Back

True or False: Java, C++ and other object oriented programming languages all support multiple inheritance?

Front

False

Back

A variable that can hold a reference to an object of class A can also hold a reference to an object belonging to any subclass of A

Front

True

Back

True or False: A variable that can hold a reference to an object of class A can also hold a reference to an object belonging to any subclass of A.

Front

True

Back

Which statement is true with respect to the following code? import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My Frame"); frame.getContentPane().add(new JButton("OK")); frame.getContentPane().add(new JButton("Cancel")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } }

Front

b. Only button Cancel is displayed.

Back

Which of the following statements are true? (pick one or more)

Front

a. A subclass contains the functionality of a superclass. b. A subclass is usually extended to contain more functions and more detailed information than its superclass. c. "class A extends B" means A is a subclass of B.

Back

What array processing technique is shown in the following code sample? static void process_technique (int[] A) { for (int lastPlace = A.length-1; lastPlace > 0; lastPlace--) { int maxLoc = 0; for (int j = 1; j <= lastPlace; j++) { if (A[j] > A[maxLoc]) { maxLoc = j; } } int temp = A[maxLoc]; A[maxLoc] = A[lastPlace]; A[lastPlace] = temp; } }

Front

d. Selection sort

Back

Which method(s) sets the background color to yellow in JFrame jf? Select one or more:

Front

d. jf.setBackground(Color.YELLOW) e. jf.setBackground(Color.yellow)

Back

What events are generated by clicking a JList object?

Front

b. ActionEvent and ItemEvent

Back

Which of the following print method declarations are correct?

Front

b. public static void print (double... numbers) e. public static void print(int n, double... numbers)

Back

Which of the following keywords is required to create a subclass?

Front

a. extend

Back

In the following code, what is the printout for list2? class Test { public static void main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list2.length; i++) System.out.print(list2[i] + " "); } }

Front

c. 0 1 2

Back

True or False: The special variable this within java is used when you must specify the full name of an object within the class where it was defined

Front

True

Back

The method ..... gets the text (or caption) of the button bttn.

Front

b. bttn.getText()

Back

Consider the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } }

Front

a. The program displays 1 2 3 4

Back

True or False: In Java, an interface is a set of method instances without implementations?

Front

True

Back

Section 4

(50 cards)

Question text A programmer wishes to perform the following: create a two-dimensional array of int with 3 rows and 4 columns store a 17 into each element of the array. Which Java code (A, B, or C) should be used? a. int[][] array2D; array2D = new int[3][4]; for (int row = 0; row < 3; row++) { for (int col = 0; col < 17; col++) array2D[row][col] = 10+7; } b. int[][] array2D; array2D = new int[3][4]; for (int row = 0; row < 3; row++) { for (int col = 0; col < 4; col++) array2D[row][col] = 17; } c. int[][] array2D; array2D = new int[3][4]; for (int row = 1; row < 3; row++) { for (int col = 1; col < 4; col++) array2D[row][col] = 17;

Front

b. b.

Back

Here is the definition of the Pythagoras function: static double Pythagoras (double x, double y) { // Computes the length of the hypotenuse of a right // triangle, where the sides of the triangle are x and y. return Math.sqrt( xx + yy ); } Now, what is the result of the following statement: totalLength = 17 + Pythagoras (12,5);

Front

c. 30

Back

Which statements are true? Declaring a variable does not create an object. In Java, no variable can ever hold an object. You can create an object in Java by declaring it. A variable can only hold a reference to an object.

Front

a. All of the above

Back

Java is not a "platform-independent language".

Front

False

Back

What events are generated by clicking a JList object?

Front

b. ActionEvent and ItemEvent

Back

Object-oriented programming allows you to derive new classes from existing classes. This capability is known as:

Front

d. Inheritance

Back

A static member variable that is declared to be final can be termed a named constant , since its value remains constant for the whole time that the program is running. For example, if the member variable pulse is declared with: final static double pulse = 90.5; It is impossible to assign any other value to pulse within the confines of the program.

Front

True

Back

What are the programming constructs?

Front

a. Sequential

Back

The default layout out of a JPanel is ...

Front

a. FlowLayout

Back

What does the computer do when it executes the following statement? Color[] pallette = new Color[12];

Front

a. This is a declaration statement, that declares and initializes a variable named pallette of type Color[]. Correct b. The initial value of this variable is a newly created array that has space for 12 items. Correct c. The computer creates a new 12-element array object on the heap, and it fills each space in that array with null. Correct d. The computer allocates a memory space for the variable, pallette. Correct e. It stores a pointer to the new array object in that memory space. Correct

Back

What are the programming constructs?

Front

a. Sequential

Back

The handler (e.g., actionPerformed) is a method in ________.

Front

a. a listener object

Back

Suppose that a class definition begins: public class QuizQuestion { public int firstNum, secondNum; ... Which statements are correct? 1. It is illegal to refer to QuizQuestion .firstNum and QuizQuestion .secondNum because firstNum and secondNum are not static. 2. Whenever an object of type QuizQuestion is created, that object will contain instance variables named firstNum and secondNum, but the instance variables have to be referred to through the object, not through the class.

Front

c. 1 and 2

Back

The following definition of class Bank: public class Mortgage { static double interestRate; interestRate = 0.06;

Front

b. will not compile

Back

The following definition of class Bank: public class Mortgage { static double interestRate; interestRate = 0.06;

Front

b. will not compile

Back

True or False: When a variable declaration is executed, memory is allocated for the variable. This memory must be initialized to contain some definite value before the variable can be used in an expression. So, before a program can execute this statement: count = 40; // Give count its initial value It must declare a variable named count, thus the program must first execute: int count;

Front

True

Back

Which of the following is incorrect? i. int[] a = new int[2]; ii. int a[] = new int[2]; iii. int[] a = new int(2); iv. int a = new int[2]; v. int a() = new int[2];

Front

a. iii, iv and v

Back

Show the exact output produced by the following code segment. char[][] pic = new char[6][6]; for (int i = 0; i < 6; i++) for (int j = 0; j < 6; j++) { if ( i == j || i == 0 || i == 5 ) pic[i][j] = '*'; else pic[i][j] = '.'; } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) System.out.print(pic[i][j]); System.out.println();

Front

b. b

Back

The default layout out of a JPanel is

Front

a. FlowLayout

Back

True or False: The for loop repeats a set of statements a certain number of times until a condition is matched

Front

True

Back

What is the correct term for numbers[99]?

Front

b. index variable

Back

Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? char x = s.charAt(4);

Front

c. Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException.

Back

Look at this sequence of statements: Dog dog, dog1, dog 2, dog3; dog = new Dog(); dog1 = new Dog(); dog3 = dog1; dog2 = null; dog.name = "Cheeky"; dog1.name = "Rusty"; Now, what is the output of the following command? System.out.println(dog3); ?

Front

b. Rusty

Back

Which statements are false? A dynamic array:

Front

b. Does not allow you to put a value at a given position and get the value that is stored at a given position. Correct c. There is an upper limit on the positions that can be used.

Back

True or False: Enumerated type constants are also examples of named constants. The statement: enum color { RED, GREEN, BLUE} defines the constants color.RED, color.GREEN and color. BLUE

Front

True

Back

The method ... places a menu item mi into a menu mu

Front

a. mu.add(mi)

Back

Consider the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } }

Front

a. The program displays 1 2 3 4

Back

A program contains a switch statement that lets you test the value of an expression and, depending on that value, to jump directly to some location within the switch statement. When compiling the program, when will a Java compiler report an error?

Front

b. If the value of the expression is a String or a real number.

Back

What does the computer do when it executes the following statement? Color[] pallette = new Color[12];

Front

a. This is a declaration statement, that declares and initializes a variable named pallette of type Color[]. Correct b. The initial value of this variable is a newly created array that has space for 12 items. Correct c. The computer creates a new 12-element array object on the heap, and it fills each space in that array with null. Correct d. The computer allocates a memory space for the variable, pallette. Correct e. It stores a pointer to the new array object in that memory space. Correct

Back

Which of the following statements are true? Select one or more: a. Inner classes can make programs simple and concise. Correct b. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. Correct c. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. Correct d. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class. Correct

Front

a,b,c,d

Back

A collection of data items considered as a unit is called a?

Front

a. data structure

Back

How many items can be added into a JComboBox object?

Front

d. No limit

Back

To detect whether the right button of the mouse is pressed, use the method __________ in the MouseEvent object evt.

Front

d. evt.isMetaDown()

Back

Which of the following are subclasses of java.awt.Component?

Front

b. Swing user interface classes

Back

A variable that can hold a reference to an object of class A can also hold a reference to an object belonging to any subclass of A.

Front

True

Back

To draw things, you should override this method

Front

c. paintComponent()

Back

To detect whether the right button of the mouse is pressed, use the method __________ in the MouseEvent object evt.

Front

d. evt.isMetaDown()

Back

The handler (e.g., actionPerformed) is a method in ________.

Front

a. a listener object

Back

True or False: The conditional operator is otherwise known as the ternary operator.

Front

True

Back

True or False: A program that is written in the Java programming language must be compiled before it can be executed.

Front

True

Back

True or False: Assuming that all variables are defined, the following segment of code is invalid. if ( x > 0 ) if ( y > 0 ) x++; else y++;

Front

False

Back

Java is not a "platform-independent language".

Front

False

Back

Which of the following is incorrect? i. int[] a = new int[2]; ii. int a[] = new int[2]; iii. int[] a = new int(2); iv. int a = new int[2]; v. int a() = new int[2];

Front

a. iii, iv and v

Back

Which of the following statements are true?

Front

b. The keyPressed handler is invoked when a key is pressed. Correct c. The keyReleased handler is invoked when a key is released. Correct d. The keyTyped handler is invoked when a Unicode character is entered. Correct

Back

True or False: One of the components of a computer is its CPU, which converts the Input to the Output

Front

'False'

Back

The area of a circle of radius r is given by 3.14159*r2. Which of the following programs computes and prints the area of a circle of radius 17.42.

Front

a. a.

Back

A program contains a switch statement that lets you test the value of an expression and, depending on that value, to jump directly to some location within the switch statement. When compiling the program, when will a Java compiler report an error?

Front

b. If the value of the expression is a String or a real number.

Back

Assume double[][][] x = new double[4][5][6], what are x.length, x[2].length, and x[0][0].length?

Front

a. 4, 5, and 6

Back

The method ..... gets the text (or caption) of the button bttn.

Front

b. bttn.getText()

Back

What is the printout of the third println statement in the main method? public class Foo { int i; static int s; public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); } public Foo() { i++; s++; } }

Front

c. f3.i is 1 f3.s is 3

Back

Section 5

(3 cards)

True or False: The following code represents a syntactically valid switch statement? int x; x = 5; switch ( x ) { case 1: break; case 2: break; default: System.out.println("The choice was not found"); }

Front

True

Back

Consider the following code, which output is correct? public class Student { int age; static int age2 = 3; public static void main(String[] args) { Student student1; Student student2; Student student3; student1 = new Student(); student1.age = 10; student2 = student1; student3 = new Student(); System.out.println(student2.age+" "+student3.age2); } }

Front

a. 10 3

Back

True or False: A computer is built to carry out instructions that are written in a type of language called binary language.

Front

True

Back