Intro Into Java Ch. 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

If a method's signature is labeled ____, the message is sent to the method's class instead of to an object. a) class b) iterative c) static d) count-controlled

C

In an import package, you can substitute a class or subsection name with the ____ character to indicate that all of the subsections in the package of classes in the subsections are to be imported. a) \ b) ? c) * d) #

C

A _____ error occurs when a semicolon is missing at the end of a statement. a) syntax b) run-time c) logic d) semantic

A

A(n) ______ is a program that behaves like a computer. a) interpreter b) compiler c) terminal I/O d) applet

A

Caroline uses the ____ character to include quotation marks in the welcome message. a) escape b) output c) concatenation d) forward slash

A

Case 2-1 Jeremiah is a C++ programmer who has be asked by a client to create a program using Java. Jeremiah knows that Java is a) better suited to the internet than C++ b) more error-prone than C++ c) the world's most popular industrial-strength programming language d) superficially very different from C++

A

Consider the following two lines of code. What can you say about s1 and s2? String s1 = "testing" + "123"; String s2 = new String ("testing 123"); a) s1 and s2 are both references to different String objects. b) s1 and s2 are both references to the same String object. c) the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error d) s1 and s2 will compare "equal" e) none of the above

A

Figure 2-1 above represents a(n) ____ user interface. a) GUI b) JVM c) terminal I/O d) variable

A

Given the following assignment statement, which of the following answers is true regarding the order that the operators will be applied based on operator precedence? a = (b+c)*d/e-f; a) +, *, /, - b) +, -, *, / c) *, +, /, - d) *, /, +, - e) +, /, *, -

A

If Ari wants to change the order in which numbers are calculated, he should add ____ to them. a) parentheses b) literals c) slashes d) mixed-modes

A

In Java, "instantiation" means a) creating a new object of the class b) launching a method c) noticing the first time something is used d) creating a new alias to an existing object e) none of the above

A

Java is all of the following EXCEPT a) fast b) secure c) robust d) portable

A

Programming and natural languages share all of the following elements EXCEPT a) rigidity b) vocabulary c) syntax d) semantics

A

Suppose that the String name = "Frank Zappa". What will the instruction name.toUpperCase().replace('A', 'I'); return? a) "FRINK ZIPPI" b) "FRANK ZAPPA" c) "Frink Zippi" d) "Frank Zappa" e) "Frink ZippI"

A

The decrement operator is a) -- b) ++ c) / d) !=

A

The expression (3+5)+2*2+4 will yield ____ as the answer. a) 16 b) 20 c) 24 d) 60

A

The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as a) flow of control b) conditional statements c) try and catch d) sequentiality e) boolean execution

A

The main factor affecting a program's readability is its a) layout b) spelling c) language d) development environment

A

The string of characters that appears between parentheses following the message in Java code is called a(n) _____. a) parameter b) statement c) variable d) thread

A

Which of the following is NOT an example of a primitive data type? a) Strings b) Numbers c) Characters d) Booleans

A

You can reduce the number of logic error in a program by rereading code carefully, or a) proofreading b) debugging c) desk checking d) key wording

A

A ____ error occurs when the computer is instructed to divide by 0. a) syntax b) run-time c) logic d) semantic

B

Ari uses the expression (15+9)/(3+1)*2 to yield the value _____. a) 3 b) 12 c) 20 d) the expression is not valid

B

Boolean, if, import, and return are all examples of ______. a) user-defined symbols b) reserved words c) variables d) signatures

B

Case 2-1 Jeremiah is a C++ programmer who has be asked by a client to create a program using Java. Jeremiah will incorporate _____ into his Java program in order to allow multiple processes to occur at once, such as an image being transferred from one machine to another across a network, while another process simultaneously interacts with the user. a) variables b) threads c) panels d) applets

B

Colors in most computer system use the ____ scheme. a) color class b) RGB c) CMYK d) GUI

B

Given the nested if-else structure below; answer question below. if (a>0) if (b<0) x=x+5 else if (a>5) x=x+4; else x=x+3; else x=x+2; If x is currently 0, a=0 and b=-5, what will x become after the above statement is executed? a) 0 b) 2 c) 3 d) 4 e) 5

B

If the String major = "Computer Science", what is returned by major.charAt(1)? a) 'm' b) 'o' c) 'C' d) "C" e) "Computer"

B

If x is an int and y is a float, all of the following are legal except which assignment statement? a) y = x; b) x = y; c) y = (float)x; d) x = (int)y; e) all of the above are legal

B

In order to create a constant, you would which of the following Java reserved words? a) private b) final c) static d) class e) int

B

In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will mutation #3 yield if Mutation #1: mutation1=phrase.concat(".")? a) EINSTEIN. b) XINSTXIN. c) einstein. d) xinstxin. e) Einstein.

B

Some JVMs translate byte code instructions into machine language when they are first encountered, using the _____ technique. a) IDE b) JIT c) variable d) interpreter

B

SomeClass someObject = new SomeClass (some parameters); is an example of a) assignment b) instantiation c) byte code d) interpretation

B

Text that appears between an opening /* and a closing */ is a(n) a) end-of-line statement b) multiline comment c) debugging statement d) expression

B

What will be displayed by this command: System.out.println(Math.pow(3,3-1)); a) 4 b) 9 c) 27 d) 8 e) 6

B

What will be the result of the following assignment statement? Assume b = 5 and c = 10 int a = b*(-c+2)/2; a) -30 b) -20 c) -6 d) 30 e) 20

B

Which of the following is a difference between programming and natural languages? a) semantics b) literalness c) exception d) origin

B

Which of the following numeric data types is used for smaller, less precise floating-point numbers? a) double b) float c) short d) byte

B

Which of the following will yield a pseudorandom number in the range [-5, +5] given the following: Random gen = newRandom(); a) gen.nextInt(10)-5 b) gen.nextFloat()*10-5 c) gen.nextInt()*10-5 d) gen.nextFloat()*5 e) gen.nextFloat()*5-10

B

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0? a) if (x>0) x++; else x--; b) if (x>0) x++; else if (x<0) x--; c) if (x>0) x++; if (x<0) x--; else x=0; d) if (x==0) x=0; else ++; e) x--; x++; x--;

B

____ is when the same name is used for two different methods. a) infinite loop b) overloading c) iteration d) sentinel

B

All of the following are examples of Java vocabulary EXCEPT ______. a) = b) * c) (f-32)*/9 d) Fahrenheit

C

Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending one a student's test score. if (score >= 90) grade = 'A'; if (score >= 80) grade = 'B'; if (score >= 70) grade = 'C'; if (score >= 60) grade = 'D'; else grade = 'F'; a) This code will not work correctly under any circumstances. b) This code will work correctly in all cases. c) This code will work correctly only if grade < 70 d) This code will work correctly only if grade < 60 e) This code will work correctly only if grade >= 60

C

Figure 2-2 above represents a(n) ______ interface. a) GUI b) JVM c) terminal I/O d) variable

C

Given the following code fragment String strA = "aBcDeFg"; String strB = strA.toLowerCase(); strB = strB.toUpperCase(); String strC = strA.toUpperCase(); a) strA.equals(strC) would be true b) strB.equals(strC) would be true c) strB.compareTo(strC) would yield 0 d) strA.compareTo(strC) would yield 0 e) none of the above

C

How many times will the following loop iterate? int x = 10; while (x>0) { System.out.println(x); x--; } a) 1 time b) 11 times c) 10 times d) 0 times e) 9 times

C

Which of the following would return the last character of the String x? a) x.charAt(0); b) x.charAt(last); c) x.charAt(length(x)); d) x.charAt(x.length()-1); e) x.charAt(x.length());

D

_____ define the rules for interpreting the meaning of statements. a) syntax b) rigidity c) logic d) semantics

D

Java is a strongly typed language. What is meant by "strongly typed"? a) Variables are allowed to change types during their existence in a program but only if the change is to a narrower type b) Every variable must have an associated type before you can use it c) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type d) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be e) Variables can be used without declaring type

C

Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random(or java.util.*). What will happen when you attempt to compile and run your program? a) The program won't run, but it will compile with a warning about the missing class. b) The program will encounter a runtime error when it attempts to access any member of the Random class. c) The program won't compile-you'll receive a syntax error about the missing class. d) The program will compile, but you'll receive a warning about the missing class. e) none of the above

C

The Random class has a method nextFloat() which returns a float value between a) -1 and +1 b) 0 and 99 c) 0 and 1 d) -2,147,483,648 and +2,147,483,647 e) 1 and 100

C

The three steps to writing a Java program, in order, are ______. a) enter, edit, compile b) edit, execute, compile c) edit, compile, execute d) enter, interpret, compile

C

What value will z have if we execute the following assignment statement? float z = 5/10; a) z will equal 0.05 b) z will equal 0.5 c) z will equal 0.0 d) z will equal 5.0 e) none of the above, a run-time error arises because z is a float and 5/10 is an int

C

Which library package would you import to use the class Random? a) java.io b) java.beans c) java.util d) java.text e) java.lang

C

Which of the following is NOT true about Java? a) Java is an object-based language. b) Java creates programs that are portable. c) The Java compiler translates into machine language. d) Java supports threads.

C

Which of the following is NOT true about variables? a) Their values can change during execution. b) Before using a variable for the first time, the program must declare its type. c) The type of data a variable contains can be changed. d) All of the above are true.

C

____ errors are also called bugs. a) syntax b) run-time c) logic d) semantic

C

____ is an assignment operator. a) + b) * c) = d) all of the above

C

A ____ is used to mark the end of each statement in a program. a) comma (,) b) slash (/) c) period (.) d) semicolon (;)

D

A cast is required in which of the following situation? a) using charAt to take an element of a String and store it in a char b) storing an int in a float c) storing a float in a double d) storing a float in an int e) all of the above requires casts

D

A(n) ______ is a small Java program that runs on Web pages. a) JIT b) parameter c) JVM d) applet

D

Caroline is writing a program in Java which asks the user to input their first and last name, and then will output a welcome message. Caroline uses the _____ operator to join the first and last name strings for the welcome message. a) comment b) signature c) keyword d) concatenation

D

If x is an int where x = 1, what will x be after the following loop terminates? while (x<100) x*=2 a) 100 b) 64 c) 2 d) 128 e) none of the above, this is an infinite loop

D

In Java a variable may contain a) a class b) a method c) a package d) a value or a reference e) any of the above

D

Of the following if statements, which one correctly executes three instructions if the condition is true? a) if (x<0) a=b*2; y=x; z=a-y; { b) if (x<0) a=b*2; y=x; z=a-y; } c) if { (x<0) a=b*2; y=x; z=a-y; } d) if (x<0) { a=b*2; y=x; z=a-y; } e) B, C, and D are all correct, but not A

D

Sending a message to a variable before the corresponding object has been instantiated causes a(n) _____ expression. a) no such method b) syntax c) desk checking d) null pointer

D

The ____ character is used to indicate that punctuation such as commas and quotation marks should be taken literally. a) * b) = c) ( d) \

D

To run Java byte code, you must install a(n) a) GUI b) JIT c) IDE d) JVM

D

To use a method successfully, you must know a) what type of value it returns b) its name c) the number and type of the parameters it expects d) all of the above

D

Given the nested if-else structure below; answer questions below. if (a>0) if (b<0) x=x+5 else if (a>5) x=x+4; else x=x+3; else x=x+2; If x is currently 0, a=1 and b=-1, what will x become after the above statement is executed? a) 0 b) 2 c) 3 d) 4 e) 5

E

If a, b, and c are int variables with a=5, b=7, c=12, then the statement int z=(a*b-c)/a; will be equal to a) 5 b) -5 c) 23 d) 0 e) 4

E

If two variables contain aliases of the same object then a) the object may be modified using either alias b) the object cannot be modified unless there's but a single reference to it c) a third alias is created if/when the object is modified d) the object will become an "orphan" if both variables are set to null e) answers A and D are correct

E

If x is an int where x = 0, what will x be after the following loop terminates? while (x < 100) x*=2; a) 128 b) 2 c) 64 d) 100 e) none of the above, this is an infinite loop

E

What happens if you attempt to use a variable before it has been initialized? a) a syntax error may be generated by the compiler b) a runtime error may occur during execution c) a "garbage" or "uninitialized" value will be used in the computation d) a value of zero is used if a variable has not been initialized e) answers A and B are correct

E

What is the function of the dot operator? a) it serves to separate the integer from the fractional part of a floating point number b) it allows one to access the data within an object when given a reference to the object c) it allows one to invoke a method within an object when given a reference to the object d) it is used to terminate commands (much as a period terminates a sentence in English) e) both B and C are correct

E

Which of the following reserved words in Java is used to create an instance of a class? a) public b) class c) public or private, either could be used d) import e) new

E

Which properties are true of String objects? a) their lengths never change b) the shortest string has zero length c) the index of the first character in a string is one d) individual characters within a String may be changed using the replace method e) only A and B are true

E

True or False? A variable of type boolean will store either a 0 or a 1.

False

True or False? If x is the String "Hi There", then x.toUpperCase().toLowerCase(); will return the original version of x

False

True or False? If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package.*.*;

False

True or False? In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).

False

True or False? Java is able represent 255*255*255=16,581,375 distinct colors.

False

True or False? System.out.println("123" + 4) will display the value 127.

False

True or False? The Java graphics coordinate system is similar to the coordinate system one finds in mathematics in every respect.

False

True or False? The values of (double)5/2 and (double)(5/2) are identical

False

True or False? These two ways of setting up a String yield identical results: a) String string = new String (12345); b) String string = new String ("12345");

False

True or False? These two ways of setting up a String yield identical results: a) String string = "12345"; b) String string = 12345;

False

True or False? You may use the String replace () method to remove characters from a String.

False

True or False? Only difficult programming problems require a pseudocode solution before the programmer creates the implementation (program) itself.

False

True or False? A double is wider than a float and a float is wider than an int.

True

True or False? If String name = "George W. Bush"; then the instruction name.length(); will return 14.

True

True or False? If x is a string, then x = new String ("OH"); and x = "OH"; will accomplish the same thing.

True

True or False? In Java, 'a' and 'A' are considered to be different values.

True

True or False? Many Java drawing shapes are specified using a bound rectangle.

True

True or False? There are three way that data conversion may occur--by assignment, by promotion, by casting.

True

True or False? These two ways of setting up a String yield identical results: a) String string = new String ("123.45"); b) String string = "" + 123.45;

True

True or False? These two ways of setting up a string yield identical results: a) String string = new String ("string"); b) String string = "string";

True

True or False? When comparing any primitive type of variable, == should always be used to test to see if two values are equal.

True

True or False? You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int, float, or double.

True

True or False? If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns true

True


Conjuntos de estudio relacionados

Chapter 10 - Buying, Using, Disposing

View Set

Chapter 3: Policy Provisions, Options, and Other Features

View Set

C# Ch 1, C# Ch2, Chapter 3, Chapter 7, Chapter 8, Chapter 9

View Set

Property Valuation and Financial Analysis (14%)

View Set

Anatomy Chapter 7 Skeletal Worksheets Part 2

View Set

ch. 10-The foreign exchange market

View Set