CSIT Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? a. (x <= 15 || x >= 2) b. (2 <= x || x <= 15) c. (x >= 2 && x <= 15) d. (2 <= x <= 15)

(x >= 2 && x <= 15)

In Java, array indexes always begin at ________. a. 0 b. 2 c. -1 d. 1 e. You can declare an array to have any indexes you choose.

0

What is the value of i after the following code fragment? int i = 5; switch(i) { case 0:i = 15;break; case 1:i = 25;break; case 2:i = 35;break; case 3:i = 40;break; default:i = 0; } a. 0 b. 15 c. 35 d. 40 e. 25

0

What are the valid indexes for the array shown below? int [] myArray = new int [25]; a. 0-24 b. 0-25 c. 1-24 d. 1-25

0-24

Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x <= 3) { y += 2; x += 1; } a. 6 b. 8 c. 10 d. 2

10

What will be the output of the following code snippet? int[] array = new int[25]; System.out.println(array.length); a. 24 b. 26 c. 25 d. This code will result in a compile time error. e. This code will result in a run time error.

25

Which of the following is not a valid Java identifier? a. answer_7 b. highest$ c. 2ndlevel d. thirdNumber e. anExtremelyLongIdentifierIfYouAskMe

2ndlevel

Consider the expression: result = 15 % 4; a. 4 b. 0 c. 2 d. 3 e. 1

3

Consider the following snippet of code: System.out.println("30 plus 25 is " + 30 + 25); What is printed by this line? a. 30 plus 25 is 3025 b. 30 plus 25 is 55 c. 30 plus 25 is 30 d. 30 plus 25 is 25 e. This snippet of code will result in a compiler error.

30 plus 25 is 3025

Given the following code, what is the final value of i? int i; for(i = 0; i <= 4;i ++ ) { System.out.println(i); } a. 3 b. 4 c. 5

5

Consider the following snippet of code: int firstNum = 25; int seconNum = 3; double result = 25/3; System.out.println(result); What is output by this code? a. 8.3 b. 8.333333333 c. 8.0 d. 8 e. This snippet of code will result in a compiler error

8.0

Which of the following IS NOT a valid relational operator in Java? a. <= b. > c. == d. <> e. !=

<>

__________ parameters are the values that are used when calling a method. a. Informal b. Formal c. Actual d. Useful e. none of the above

Actual

Which of the following array declarations are invalid? a. int[] grades = new int[5]; b. int grades[] = new int[5]; c. int[] grades = { 91, 83, 42, 100, 77 }; d. All of the above are valid. e. None of the above are valid.

All of the above are valid.

Which of the following is an invalid way to instantiate a String object? a. String title = new String("Java Software Solutions"); b. String name = "John Lewis"; c. String empty = ""; d. String alsoEmpty = new String(""); e. All of the above are valid.

All of the above are valid.

Dividing by zero will throw which exception? a. FileNotFoundException b. NumberFormatException c. ArrayIndexOutofBoundsException d. ArithmeticException e. none of the above

ArithmeticException

What is wrong with the following code fragment? final int SIZE = 5; double scores[SIZE]; for(int i = 0; i <= SIZE;i ++) { System.out.print( "Enter a score "); scores[i] = scan.nextDouble(); } a. Arrays must be integers. b. Array indexes start at 1 not 0. c. Should be scores[0] = scan.nextDouble(); d. Array indexes must be less than the size of the array.

Array indexes must be less than the size of the array.

What exception will the following source code throw? for(int i = 0; i <= myArray.length; i++) System.out.println(myArray[i]) a. ArithmeticException b. ArrayIndexOutofBoundsException c. NumberFormatException d. FileNotFoundException e. none of the above

ArrayIndexOutofBoundsException

Which of the following is a true statement? a. Arrays cannot be passed as parameters to methods. b. Arrays are passed as parameters to methods like object types. c. Arrays are passed as parameters to methods like primitive types. d. All of the above are true. e. None of the above are true.

Arrays are passed as parameters to methods like object types.

Given the following declarations, which of the following is a legal call to this method? int myMethod(int myValue) int [] myArray = new int[1000]; a. myArray = myMethod(myArray); b. System.out.println(myMethod(myArray[1])); c. System.out.println(myMethod(myArray)); d. System.out.println(myMethod(myArray[0])); e. B and D

B and D

Which of the following classes play a role in altering a visual aspect of a component? a. ColorChooser b. BorderFactory c. ColorCreator d. ToolTip e. none of the above

BorderFactory

Which of the following layout managers organize the components from left to right, starting new rows as necessary? a. Flow Layout b. Card Layout c. Border Layout d. Box Layout e. Grid Layout

Flow Layout

Which of the following best describes a timer component? a. It determines the amount of time it takes to execute a method. b. It generates action events at regular intervals. c. It starts when a GUI component is first initialized, and ends when it is destroyed. d. A timer cannot be considered a GUI component. e. Every object has a timer, and it is implicitly activated in the constructor of the object.

It generates action events at regular intervals.

What is the precedence of the index operator ([ ] ) relative to other operators in Java? a. It has the lowest precedence of all Java operators. b. It has a higher precedence than multiplication, but a lower precedence than addition. c. [ ] is not an operator. d. It has a higher precedence than addition, but a lower precedence than multiplication. e. It has the highest precedence of all Java operators.

It has the highest precedence of all Java operators.

The Java compiler translates Java source code into ______. a. an object-oriented language b. Java bytecode c. assembly code d. machine code e. C++

Java bytecode

Which of the following are true about two-dimensional arrays? a. Two-dimensional arrays are not accessible using for loops. b. Two-dimensional arrays can only store up to 10 elements per array (or per row). c. Two-dimensional arrays cannot hold objects. d. Two-dimensional integer arrays cannot be initialized via an initializer list. e. None of the above are true.

None of the above are true.

Assigning "A" to int num; will throw what exception? a. none of the above b. NumberFormatException c. ArrayIndexOutofBoundsException d. FileNotFoundException e. ArithmeticException

NumberFormatException

Which of the following statements best describes the flow of control in the main method of a Java program that has no conditionals or loops? a. Program statements are executed linearly, with earlier statements being executed first. b. Program statements are executed linearly, with later statements being executed first. c. Program statements are all executed at the same time. d. Program statements are executed according to their priority, which is specified by the programmer. e. Some program statements are executed at the same time, and others are executed in a linear manner.

Program statements are executed linearly, with earlier statements being executed first.

Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this? a. String prefix = listing.front(5); b. String prefix = listing.front(6); c. String prefix = listing.substring(1,5); d. String prefix = listing.substring(0,5); e. String prefix = listing.firstChars(5);

String prefix = listing.substring(0,5);

Which of the following represents the standard input stream? a. System.out b. System.in c. System.err d. System.instream e. System.outstream

System.in

Given the following code fragment, what is the output? int x = 5; if( x > 5) System.out.println("x is bigger than 5."); System.out.println("That is all."); System.out.println("Goodbye"); a. Goodbye b. x is bigger than 5. That is all c. x is bigger than 5 d. That is all. Goodbye

That is all. Goodbye

Which of the following event descriptions best describes the mouse entered event? a. The mouse button is pressed down. b. The mouse button is pressed down and released without moving the mouse in between. c. The mouse pointer is moved onto a component. d. The mouse button is released. e. The mouse is moved while the mouse button is pressed down.

The mouse pointer is moved onto a component.

Which of the following is not an arithmetic operation in Java? a. - b. + c. * d. % e. These are all arithmetic operations in Java.

These are all arithmetic operations in Java.

Which of the statements is true about the following code snippet? int[] array = new int[25]; array[25] = 2; a. The integer value 25 will be assigned to the third value in the array. b. This code will result in a run-time error. c. The integer value 2 will be assigned to the last index in the array. d. This code will result in a compile-time error. e. The integer value 25 will be assigned to the second index in the array.

This code will result in a run-time error.

Which of the following statements best describes this line of code? int[] numbers = new int[50]; a. This is a declaration and initialization of an integer array that will hold integers smaller than 49. b. This is the declaration and initialization of an array that holds 50 integers. c. This is a declaration and initialization of an array that holds 49 integers. d. This is a declaration and initialization of an integer array that will hold integers smaller than 50. e. None of the above is correct.

This is the declaration and initialization of an array that holds 50 integers.

The Exception class and the Error class are subclasses of the ________ class. a. Catchable b. Throwable c. RuntimeProblem d. CompilerProblem e. none of the above

Throwable

A __________ diagram helps us visualize the contents of and relationships among the classes of a program. a. public b. UML c. private d. class and object e. object-oriented

UML

A(n) ____________ is a step-by-step process for solving a problem. a. class b. algorithm c. aggregate object d. UML diagram e. none of the above

algorithm

Which of the following is a fundamental idea of good GUI design? a. Be consistent. b. Optimize user abilities. c. Prevent user errors. d. Know the user. e. all of the above

all of the above

Which of the following might be included in an IDE? a. an editor b. a compiler c. a debugger d. all of the above e. none of the above

all of the above

Which boolean operation is desrcibed by the following table? A - B - Operation True - True - True True - False - False False - True - False False - False - False a. and b. not c. or d. none of the above

and

Which of the following statements will assign the first command-line argument sent into a Java program to a variable called argument? a. argument = System.getArgument[0]; b. argument = System.getArgument[1]; c. argument = args[1]; d. argument = args[0]; e. argument = System.getFirstArgument();

argument = args[0];

Which of the following data types only allows one of two possible values to be assigned? a. float b. char c. boolean d. int e. long

boolean

Which of the following lines is a properly formatted comment? a. /** this is a comment **/ b. / This is a comment / c. // This is a comment d. both A and C e. A, B and C

both A and C

Suppose we want to condition an if statement on whether two String objects, referenced by stringOne and stringTwo, are the same. Which of the following is the correct way to achieve this? a. if(stringOne == stringTwo) b. if(stringOne.compareTo(stringTwo)) c. if(stringOne.equals(stringTwo)) d. if(stringOne != stringTwo) e. if(stringOne = stringTwo)

c. if(stringOne.equals(stringTwo))

A(n) ________ can be used to find the exact line where an exception was thrown during program execution. a. call-stack trace b. interface c. try block d. catch block e. none of the above

call-stack trace

Which of the following are valid case statements in a switch? a. case 'ab': b. case 1.5: c. case 1: d. case x < 4;

case 1:

A(n) ________ is used to specify how certain exceptions should be handled. a. finally block b. try block c. error d. catch block e. none of the above

catch block

Which of the following components can be toggled on or off using the mouse, indicating that a particular boolean condition is set or unset? None, one, or many of this component type may be selected. a. radio button b. slider c. dialog box d. check box e. none of the above

check box

Which of the following exception types must always be caught unless they are contained in methods that throw them in the method header? a. file stream b. checked c. unchecked d. IO e. none of the above

checked

Which of the following components allows the user to select one of several options from a "drop down" menu? a. sliders b. check boxes c. combo boxes d. radio buttons e. none of the above

combo boxes

A(n) ________ is an object that defines a screen element used to display information or allow the user to interact with a program in a certain way. a. component b. GUI c. listener d. AWT e. event

component

Which of the following types of methods do not have any return type (not even a void return type)? a. methods declared as public b. methods declared as static c. constructors d. methods declared as private e. all of the above have return types.

constructors

Which of the following lines of code finds the number of characters in String list and assigns the value to count? a. count =list.count(); b. list = list.count(); c. count = list.length(); d. count = length.list(); e. None of the above

count = list.length();

A(n) ________ is a graphical window that pops up on top of any currently active window so that the user can interact with it. a. listener b. component c. dialog box d. event e. none of the above

dialog box

A _____________ loop always executes its loop body at least once. a. do b. while c. repeat d. for e. There are no loop structures with this property in Java.

do

Which of the following object-oriented principles refers to the fact that an object should have its data guarded from inappropriate access? a. encapsulation b. inheritance c. instance variables d. polymorphism e. methods

encapsulation

A(n) ________ is an object that defines an erroneous situation from which the program usually cannot recover. a. try block b. exception c. catch block d. error e. interface

error

A(n) ________ is an object that defines an unusual or erroneous situation that is typically recoverable. a. exception b. try block c. interface d. catch block e. error

exception

Which of the following represents a dialog box that allows the user to select a file from a disk or other storage medium? a. tool tip chooser b. color chooser c. file chooser d. disk chooser e. none of the above

file chooser

To make a variable a constant which modifier must be included in its declaration? a. public b. private c. static d. final e. void

final

Every line of a(n) ________ is executed no matter what exceptions are thrown. a. catch block b. call stack trace c. finally block d. interface e. try block

finally block

Which of the following for loop headers will cause the body of the loop to be executed 10 times? a. for(int i = 0; i <= 10; i++) b. for(int i = 0; i < 10; i++) c. for(int i = 1; i <= 11; i++) d. for(int i = 1; i < 10; i++) e. None of these for loops will execute the loop body 10 times.

for(int i = 0; i < 10; i++)

Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not correctly process each element in the array? a. for(int i = 0; i < names.length; i++) b. for(String name : names) c. for(int i = 0; i < names.length(); i++) d. None of these will correctly process each element. e. All of these will correctly process each element.

for(int i = 0; i < names.length(); i++)

Which of the following will correctly assign all the values in one array to the other array? (Assume both arrays are of the same type and have SIZE elements) a. array1 = array2; b. for(int i = 0;i < SIZE;i ++) array1[ ] = array2[ ]; c. for(int i = 0;i < SIZE;i ++) array1[i] = array2[i]; d. array1[ ] = array2;

for(int i = 0;i < SIZE;i ++) array1[i] = array2[i];

GUI is an acronym for ________. a. graphical user interface b. graphical UML implementation c. graphical UML interface d. graphical user implementation e. none of the above

graphical user interface

A ________ container is one that is managed by the underlying operating system on which the program is run, whereas a ________ container is managed by the Java program itself. a. applet content pane b. lightweight, heavyweight c. heavyweight, lightweight d. content pane, applet e. none of the above

heavyweight, lightweight

Which of the following lines allows a programmer to use the Scanner class in a Java program? a. using Scanner; b. import java.util.Scanner; c. include Scanner; d. include java.util.Scanner; e. Any of the above will allow the programmer to use the Scanner class.

import java.util.Scanner;

Which of the following is an example of an invalid assignment or declaration statement? a. int money, dollars = 0, cents = 0; b. int length, meters, centimeters, millimeters; c. int age = 30; d. int years = 1; months = 12; days = 365; e. none of the above

int years = 1; months = 12; days = 365;

Which of the following is a valid declaration for a two-dimensional array? a. int[][] matrix; b. int[2] matrix; c. int[]** matrix; d. int[] matrix; e. None of these are correct.

int[][] matrix;

Java has two basic kinds of numeric values: ________, which have no fractional part, and ________ which do. a. integers, floating points b. shorts, longs c. characters, bytes d. doubles, floating points e. integers, longs

integers, floating points

Executing one or more statements one or more times is known as a. selection b. sequence c. algorithm d. iteration

iteration

Every Java array is a(n) ________, so it is possible to use a foreach loop to process each element in the array. a. iterator b. object c. operator d. class e. none of the above

iterator

Given the following code fragment, and an input value of 5, what is the output? int x; if( x < 3) { System.out.println("small"); } else { if( x < 4) { System.out.println("medium"); } else { if( x < 6) { System.out.println("large"); } else { System.out.println("giant"); } } } a. medium b. large c. giant d. small

large

A container is governed by a(n) ________, which determines exactly how the components added to the panel will be displayed. a. JPanel object b. event c. content pane d. layout manager e. JFrame object

layout manager

A(n) ________ is an object that waits for an event to occur and responds in some way when it does. a. panel b. listener c. GUI d. component e. frame

listener

The _________ of an object define its potential behaviors. a. name b. methods c. white spaces d. attributes e. variables

methods

Which of the following is considered a logical error? a. multiplying two numbers when you meant to add them b. misspelling an identifier c. typing a curly bracket when you should have typed a parenthesis d. dividing by zero e. forgetting a semicolon at the end of a programming statement

multiplying two numbers when you meant to add them

The ________ operator is used to instantiate an object. a. new b. - c. static d. + e. none of the above

new

What exception will be thrown for this statement if the file is on the c drive: inFile = new Scanner(new File("e:\\num.dat")); a. NumberFormatException b. ArrayIndexOutofBoundsException c. ArithmeticException d. all of the above e. none of the above

none of the above

Which of the following are examples of invalid string literals? a. "" b. "4 score and 7 years ago, our forefathers brought forth..." c. "Hello World!" d. "z" e. none of the above

none of the above

Which of the following components allows the user to enter typed input from the keyboard? a. check boxes b. sliders c. radio buttons d. combo boxes e. none of the above

none of the above

Which of the following lines of code accesses the second element of the first array in a two-dimensional array of integers, numbers, and stores the result in a variable called num? a. num = numbers[1][2]; b. num = numbers[0][1]; c. num = numbers.getElement(1, 2); d. num = numbers.getElement(0, 1); e. None of the above are correct.

num = numbers[0][1];

In Java, an identifier that is made up by the programmer can consist of ______. a. numbers, letters, the underscore ( _ ), and the dollar sign ( $ ) b. only numbers c. any characters d. only letters, the underscore ( _ ), and the dollar sign ( $ ) e. only letters

numbers, letters, the underscore ( _ ), and the dollar sign ( $ )

Which boolean operation is described by the following table? A - B - Operation True - True - True True - False - True False - True - True False - False - False a. and b. not c. or d. none of the above

or

A method that has multiple definitions is an ________ method. a. overloaded b. overridden c. overlooked d. overclocked e. none of the above

overloaded

When applied to instance variables, the ________ visibility modifier enforces encapsulation. a. static b. final c. public d. private e. none of the above

private

Which of the following method declarations correctly defines a method with a variable length parameter list? a. public int average(int[] list) b. public int average(int ... list) c. public int average(int a, int b, int c, ...) d. public int average(...) e. public int average(integers)

public int average(int ... list)

Which of the following method headers is most likely a header for a mutator method? a. public int getAge() b. public double computeSalary() c. public Person() d. public void setAge(int newAge) e. None of these are headers for a mutator method.

public void setAge(int newAge)

Multi-dimensional arrays that contain arrays of different lengths in any one dimension are called ________. a. static arrays b. two-dimensional arrays c. ragged arrays d. overloaded arrays e. constant arrays

ragged arrays

Assume that we have a Random object referenced by a variable called generator. Which of the following lines will generate a random number in the range 5-20 and store it in the int variable randNum? a. randNum = generator.nextInt(16) + 5; b. randNum = generator.nextInt(16) + 6; c. randNum = generator.nextInt(15) + 6; d. randNum = generator.nextInt(15) + 5; e. none of the above

randNum = generator.nextInt(16) + 5;

Which of the following lines of code appends the string Course to the String name to produce String reg? a. reg = name.append(" Course"); b. name = reg.concat(" Course); c. reg = (" Course).concat(name); d. reg = name.concat(" Course"); e. none of the above

reg = name.concat(" Course")

Which of the following expressions correctly compute 5 + 2^6? a. result = 5 + 2^6; b. result = 5 + 2*exponent(6); c. result = 5 + 2*Math.exponent(6); d. result = 5 + Math.pow(2, 6); e. none of the above

result = 5 + Math.pow(2, 6)

Given an array named scores with 25 elements, what is the correct way to access the 25th element? a. scores[24] b. scores[25] c. scores[last] d. scores+25

scores[24]

Methods that can be called directly through the class name and do not need to have an object instantiated are called ________. a. static b. public c. final d. private e. none of the above

static

If an exception is not caught, a program will ________. a. terminate abnormally b. not compile c. print a message and continue executing d. all of the above e. neither A, B nor C

terminate abnormally

Which of the following describes the act of ensuring that a program solves the intended problem in all cases? a. establishing the requirements b. testing c. implementing the design d. preliminary practice coding e. creating a design

testing

The ________ statement is used to begin exception propogation. a. except b. relay c. propogate d. throw e. send

throw

A(n) ________ is used to identify a block of statements that may cause an exception. a. error b. try block c. call-stack trace d. catch block e. none of the above

try block

All methods (with the exception of constructors) must specify a return type. What is the return type for a method that does not return any values? a. int b. public c. double d. void e. none of the above

void


संबंधित स्टडी सेट्स

Reading Comprehension: Making Sense of Literature

View Set

Hypothesis Testing and P values quiz

View Set

note taking guide 1.1-2.3 (what is health?)

View Set

How to work in groups Final Exam - Bergetha High School

View Set

Precalculus Solving for x using inverse trig functions

View Set

S66 FSA: Investment Advisers Act of 1940

View Set