Computer Programming final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

The filename for the public class that begins with public class Addition must be public.java. public.class.java. Addition.java. addition.java.

Addition.java.

Which of the following can be used in a switch statement in the expression after keyword case?A. a constant integral expression.B. a character constant.C. a StringD. an enumeration constant. A and B. A and C. B and C. All.

All.

Which of the following is not represented graphically in activity diagrams for control structures? Transition arrow. Attribute. Action state. Decision symbol.

Attribute

Which of the following is not an algorithm? A recipe. Operating instructions. Textbook index. Shampoo instructions (lather, rinse, repeat).

Textbook index.

What data type should be used to represent the following: "Bob"? String int double char It cannot be done.

String

Programs remember numbers and other data in the computer's memory and access that data through program elements called comments. messages. integers. variables.

variables

Given the following code, how will the output be displayed?System.out.print( "Hello World!\nThis is Java!" ); It will be displayed on two separate lines. It will be displayed on two separate lines with a blank line between the two messages. It will be displayed on one line as is. It will be displayed on one line with a tab space between the two messages. The \n will cause a syntax error. So there will be no output.

It will be displayed on two separate lines.

Which of the following statements is false? You should not call methods from constructors. Nested if statements can be useful for validating values. Logical operators can express nested if statements more concisely. One problem with calling methods from constructors is that it can lead to duplicated validation code.

One problem with calling methods from constructors is that it can lead to duplicated validation code.

Which operator can be used in string concatenation? * += ++ =+

+=

Which of the following would not be used to clarify a dangling-else? Indentation. Parentheses (). Braces {}. Comment //.

Parentheses ().

When method printf requires multiple arguments, the arguments are separated with ________. colons (:). semicolons (;). commas (,). periods (.).

commas (,).

java's predefined classes are grouped into packets. declarations. Galleries. packages.

packages.

Information is passed to a method in ________. the method name that method's return the method body the arguments to the method

the arguments to the method

Variables should be declared as fields only if ________. they are local variables they are used only within a method they are required for use in more than one method or their values must be saved between calls to the class's methods they are arguments

they are required for use in more than one method or their values must be saved between calls to the class's methods

Each class you create becomes a new ________ that can be used to declare variables and create objects. package instance library type.

type

Stacks are known as ________ data structures. FIFO. FILO. LIFO. LILO.

LIFO.

Which statement is false? Classes are reusable software components. A class is to an object as a blueprint is to a house. Performing a task in a program requires a method. A class is an instance of its object.

A class is an instance of its object.

Which of the following statements is true? Interpreted programs run faster than compiled programs. Compilers translate high-level language programs into machine language programs. Interpreter programs typically use machine language as input. None of the above.

Compilers translate high-level language programs into machine

Which of the following is not one of the three general types of computer languages? Machine languages. Assembly languages. High-Level languages. Spoken languages.

Spoken languages.

Given the following code, what data type will be as the output?int x; double y;y = x;System.out.println( y ); double float long int None of the above

double

What will the following code display?double[ ] myList = new double[5];myList[0] = 1.9;myList[1] = 5;myList[2] = 4.2;myList[3] = 7.4;myList[4] = 235.98;System.out.println( myList[0] ); 1.9 235.98 Nothing A logic error will occur. A run-time error will occur.

1.9

Which of the following statements about the continue statement is true? The continue statement is used to exit a repetition structure early and continue execution after the loop. The continue statement is used to continue after a switch statement. The continue statement does not alter the flow of control. A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement.

A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement.

Which of the following statements is true? When you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster. You send messages to an object; each message is implemented as a method call that tells a method of the object to perform its task. A program might call a bank-account object's deposit method to increase the account's balance. All of the above statements are true.

All of the above statements are true.

A static method can ________. call only other static methods of the same class directly manipulate only static fields in the same class directly be called using the class name and a dot (.) All of the above.

All of the above.

Counter-controlled repetition requires A control variable and initial value. A control variable increment (or decrement). A condition that tests for the final value of the control variable. All of the above.

All of the above.

Which of the following statements is true? Performing a task in a program requires a method. A method houses the program statements that actually perform its tasks. The method hides its statements from its user, just as the accelerator pedal of a car hides from the driver the mechanisms of making the car go faster. All of the above.

All of the above.

For the code segment below: switch(q){case 1:System.out.println("apple");break;case 2:System.out.println("orange");break;case 3:System.out.println("banana");break; case 4: System.out.println("pear");case 5:System.out.println("grapes");default:System.out.println("kiwi");}Which of the following values for q will result in kiwi being included in the output? 2. Any integer less than 1 and greater than or equal to 4. 1. 3.

Any integer less than 1 and greater than or equal to 4.

Which of the following statements is false? An object's attributes are specified as part of the object's class. A bank-account object would likely have a balance attribute that represents the amount of money in the account. c. Each bank-account object knows the balance in the account it represents, but not the balances of the other accounts in the bank. Attributes are specified by the class's methods.

Attributes are specified by the class's methods.

What will the following code display?public class switchMonth {public static void main( String[] args ) {int month = 8;switch (month) {case 1: System.out.println("January"); break;case 2: System.out.println("February"); break;case 3: System.out.println("March"); break;case 4: System.out.println("April"); break;case 5: System.out.println("May"); break;case 6: System.out.println("June"); break;case 7: System.out.println("July"); break;case 8: System.out.println("August"); break;case 9: System.out.println("September"); break;case 10: System.out.println("October"); break;case 11: System.out.println("November"); break;case 12: System.out.println("December"); break;default: System.out.println("Invalid month.");break;}} // End of main} // End of switchMonth Nothing January August Invalid Month A logic error will occur.

August

Which of the following statements is false? Most classes you'll use in Java programs must be imported explicitly. There's a special relationship between classes that are compiled in the same directory. By default, such classes are considered to be in the same package—known as the default package. Classes in the same package are implicitly imported into main. An import declaration is not required when one class in a package uses another in the same package.

Classes in the same package are implicitly imported into main.

What is a good systematic method for developing a computer program? Code then run it only one time. Code then run it. Modify the code if necessary then run the program again, continuing until expected results are displayed. Code then run it. If it does not work, run it again. Run it as few times as possible to avoid problems with the IDE, such as Eclipse or NetBeans. There is no need for a systematic method. The IDE will take care of the program after its code is entered.

Code then run it. Modify the code if necessary then run the program again, continuing until expected results are displayed

A decision symbol in an activity diagram takes the shape of a ________. Diamond. Rectangle. Circle. Triangle.

Diamond.

Which of the following statements is false? Each class can be used only once to build many objects. Reuse helps you build more reliable and effective systems, because existing classes and components often have undergone extensive testing, debugging and performance tuning. Just as the notion of interchangeable parts was crucial to the Industrial Revolution, reusable classes are crucial to the software revolution that has been spurred by object technology. Avoid reinventing the wheel—use existing high-quality pieces wherever possible. This software reuse is a key benefit of object-oriented programming.

Each class can be used only once to build many objects.

Which of the following statements is true? Local variables are automatically initialized. Every instance variable has a default initial value—a value provided by Java when you do not specify the instance variable's initial value. The default value for an instance variable of type String is void. The argument types in the method call must be identical to the types of the corresponding parameters in the method's declaration.e.

Every instance variable has a default initial value—a value provided by Java when you do not specify the instance variable's initial value.

Which of the following statements is false? If a method does not return a value, the return-value-type in the method declaration can be omitted. Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error. Redeclaring a method parameter as a local variable in the method's body is a compilation error. Forgetting to return a value from a method that should return a value is a compilation error.

If a method does not return a value, the return-value-type in the method declaration can be omitted.

Which of the following statements is false? Object-oriented programming is today's key programming methodology. Java has become the language of choice for implementing Internet-based applications and software for devices that communicate over a network. Software commands computer hardware to perform tasks. In use today are more than a trillion general-purpose computers and trillions more Java-enabled cellphones, smartphones and other handheld devices.

In use today are more than a trillion general-purpose computers and trillions more Java-enabled cellphones, smartphones and other handheld devices.

Which of the following will not help prevent infinite loops? Include braces around the statements in a do...while statement. Ensure that the header of a for or while statement is not followed by a semicolon. If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed. If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.

Include braces around the statements in a do...while statement

What is an Integrated Development Environment (IDE), such as NetBeans or Eclipse? It is hardware for using Java, from coding to compiling to running a program. It is hardware for installing Java on a computer. It is software for detecting Java on a computer. It is software for installing Java on a computer. It is software for using Java, from coding to compiling to running a program.

It is software for using Java, from coding to compiling to running a program.

Given the following code, how will the output be displayed? JOptionPane.showMessageDialog( null, "Hello World!\nThis is Java!" ); It will be displayed in a dialog box on two separate lines. It will be displayed in a dialog box with a blank line between the two messages. It will be displayed in a dialog box with one line as is. It will be displayed in a dialog box with a tab space between the two messages. The \n will cause syntax errors because it cannot be used in a dialog box.

It will be displayed in a dialog box on two separate lines.

What is output by the following Java code segment?int temp = 180;if (temp > 90){System.out.println("This porridge is too hot.");// cool downtemp = temp - (temp > 150 ? 100 : 20);}else{if (temp < 70){System.out.println("This porridge is too cold.");// warm uptemp = temp + (temp < 50 ? 30 : 20);}}if (temp == 80)System.out.println("This porridge is just right!"); This porridge is too hot. This porridge is too cold.This porridge is just right! This porridge is just right! None of the above.

None of the above.

________ models software in terms similar to those that people use to describe real-world objects. Object-oriented programming Object-oriented design Procedural programming None of the above

Object-oriented design

Which of the following statements is false? In the UML, each class is modeled in a class diagram as a rectangle with three compartments. The top one contains the class's name centered horizontally in boldface. The middle one contains the class's attributes, which correspond to instance variables in Java. The bottom one contains the class's operations, which correspond to methods and constructors in Java. UML represents instance variables as an attribute name, followed by a colon and the type. Private attributes are preceded by the keyword private in the UML. The UML models operations by listing the operation name followed by a set of parentheses. A plus sign (+) in front of the operation name indicates that the operation is a public.

Private attributes are preceded by the keyword private in the UML.

RAM is memory that temporarily stores data and instructions, also called primary or main memory. RAM stands for which of the following? Random Access Memory Read Access Memory Remarkable Access Memory Rich Access Memory Right Access Memory

Random Access Memory

The empty statement is denoted by what symbol? Semicolon ; Parentheses () Braces {} Colon :

Semicolon ;

Which of the following statements is true? Strings can be used in a switch statement's controlling expression and in its case labels. Strings can be used in a switch statement's controlling expression but not in its case labels. Strings cannot be used in a switch statement's controlling expression but can be used in its case labels. Strings cannot be used in a switch statement's controlling expression and cannot be used in its case labels.

Strings can be used in a switch statement's controlling expression and in its case labels.

A Java program will not compile if you have an error caused by a violation of Java's syntax rules. What is this error called? Compiler Logic Syntax Run-Time Comment

Syntax

Which of the following statements is true? Both syntax errors and logic errors are caught by the compiler. Both syntax errors and logic errors have effects at execution time. Syntax errors are caught by the compiler. Logic errors have effects at execution time. Logic errors are caught by the compiler. Syntax errors have effects at execution time.

Syntax errors are caught by the compiler. Logic errors have effects at execution time.

Which of the following statement displays Hello World? System.out.printf( "%2s", "Hello " "World" ); System.out.printf( "%s %s", "Hello", "World" ); System.out.printf( "%s%s", "Hello, World" ); System.out.printf( "s% s%", "Hello", "World" );

System.out.printf( "%s %s", "Hello", "World" );

What is the correct syntax for displaying the message, Hello World? system.out.println( Hello World ); System.Out.println( "Hello World" ); System.out.println( "Hello World" ); System.Out.Println( "Hello World" ); SYSTEM.OUT.PRINTLN( "Hello World" );

System.out.println( "Hello World" );

Which of the following statements would display the phase Java is fun? System.out.println( "hellois fun\rJava " ); System.out.println( 'Java is fun' ); System.out.println( "\"Java is fun\"" ); System.out.println( Java is fun );

System.out.println( "hellois fun\rJava " );

Which of the following statements about a do...while repetition statement is true? The body of a do...while loop is executed only if the terminating condition is true. The body of a do...while loop is executed only once. The body of a do...while loop is always executed at least once. None of the above.

The body of a do...while loop is always executed at least once.

Which of the following statements about the break statement is false? The break statement is used to exit a repetition structure early and continue execution after the loop. A break statement can only break out of an immediately enclosing while, for, do...while or switch statement. The break statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.

The break statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

Which of the following statements is false? The javac command can compile multiple classes at once; simply list the source-code filenames after the command with each filename separated by a comma from the next. If the directory containing the app includes only one app's files, you can compile all of its classes with the command javac *.java. The asterisk (*) in javac *.java indicates that all files in the current directory ending with the filename extension ".java" should be compiled. All of the above are true.

The javac command can compile multiple classes at once; simply list the source-code filenames after the command with each filename separated by a comma from the next.

For the two code segments below: Segment A int q = 5;switch(q){case 1:System.out.println(1);case 2:System.out.println(2);case 3:System.out.println(3);case 4:System.out.println(4);case 5:System.out.println(5);default:System.out.println("default");} Segment Bq = 4;switch(q){case 1:System.out.println(1);case 2:System.out.println(2);case 3:System.out.println(3);case 4:System.out.println(4);case 5:System.out.println(5);default:System.out.println("default");} Which of the following statements is true? The output for Segment A is: default The output for Segment B is:4 The output for Segment B is: 45default The output for Segment A is:5default

The output for Segment A is:5default

Which of the following statements about the conditional operator (?:) is false? The conditional operator is a ternary operator, meaning that it takes three operands. The first operand is a boolean expression. The second operand is the result value if the condition evaluates to false. The second operand is the result value if the condition evaluates to true.

The second operand is the result value if the condition evaluates to false.

What is output by the following Java code segment?int temp = 180;while (temp != 80){if (temp > 90){System.out.print("This porridge is too hot! ");// cool downtemp = temp - (temp > 150 ? 100 : 20);}else{if (temp < 70){System.out.print("This porridge is too cold! ");// warm uptemp = temp + (temp < 50 ? 30 : 20);}}}if (temp == 80)System.out.println("This porridge is just right!"); This porridge is too cold! This porridge is just right! This porridge is too hot! This porridge is just right! This porridge is just right! None of the above.

This porridge is too hot! This porridge is just right!

Which of the following statements is false? Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String. To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments. A class instance creation expression begins with keyword new and creates a new object. A constructor is similar to a method but is called implicitly by the new operator to initialize an object's instance variables at the time the object is created.

To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

End-of-line comments that should be ignored by the compiler are denoted using Two forward slashes ( // ). Three forward slashes ( /// ). A slash and a star ( /* ). A slash and two stars ( /** ).

Two forward slashes ( // ).

Which of the following statements is true? The UML models a parameter of an operation by listing the parameter name, followed by a colon and the parameter value between the parentheses after the operation name. The UML indicates an operation's return type by placing a colon and the return value after the parentheses following the operation name. UML class diagrams do not specify return types for operations that do not return values. Declaring instance variables public is known as data hiding or information hiding.

UML class diagrams do not specify return types for operations that do not return values

Which of the following statements about the switch statement is false? You can use Strings in a switch statement's controlling expression. You can use a String in a switch statement's case label. You can use a comma-separated list of Strings in a switch statement's case label. You cannot use a String in a switch statement's default case label.

You can use a comma-separated list of Strings in a switch statement's case label.

Which of the following escape sequences represents a carriage return? \n \r. \cr. \c.

\r.

The parameter list in the method header and the arguments in the method call must agree in: number type order all of the above

all of the above

All import declarations must be placed inside the class declaration's body. before the class declaration. after the class declaration. all of the above will work.

before the class declaration.

Which of the following data items are arranged from the smallest to the largest in the data hierarchy. records, characters, fields, bits, files. bits, files, fields, records, characters. fields, characters, bits, files, records. bits, characters, fields, records, files.

bits, characters, fields, records, files.

What data type should be used to represent the following value as numeric? 23.65 String int double char It cannot be done.

double

An import declaration is not required if you always refer to a class with its ________ name, which includes its package name and class name. compile-time default package paired fully qualified name

fully qualified name

What will the following code display? public class relationalOperators { public static void main(String args[ ]) { int i = 11; int j = 20; if ( i > j ) { System.out.println( " i is greater than j" ); } if ( i <= j ) { System.out.println( " i is less than or equal to j " ); } } End of main} // End of relationalOperators 11 i is greater than j 10 > 20 i is less than or equal to j A logic error will occur.

i is less than or equal to j

What will the following code display?for ( int i = 0; i < 1; i++ ) { System.out.print( "i is now " + i ); } i is now 0 Nothing i is now 0 i is now 1 i is now 1 A logic error will occur.

i is now 0

What's the proper way to declare an integer array of size 5? int array = new int[5]; int array = new int[4]; int array[4]; int array[5]; None of the above.

int array = new int[5];

You must call most methods other than ________ explicitly to tell them to perform their tasks. public methods main static methods private methods

main

If more method calls occur than can have their activation records stored on the program execution stack, an error known as a ________ occurs. stack overflow. stack rewind. stack full. stack empty.

stack overflow

A key part of enabling the JVM to locate and call method main to begin the app's execution is the ________ keyword, which indicates that main can be called without first creating an object of the class in which the method is declared. stable private static public

static

When an object is concatenated with a String, ________. a compilation error occurs a runtime error occurs the object's toString method is implicitly called to obtain the String representation of the object the object's class name is concatenated with the String

the object's toString method is implicitly called to obtain the String representation of the object

Consider the following Java statements:int x = 9;double y = 5.3;result = calculateValue(x, y);Which of the following statements is false? A method is called with its name and parentheses. x and y are parameters. Copies of x and y are passed to the method calculateValue. x and y are arguments.

x and y are parameters.

The body of each class declaration begins with ________ and ends with ________. (, ). [, ]. {, }. /, \.

{, }.


Ensembles d'études connexes

Chapter 3: Justification and Similarity

View Set

Cyber security Interview questions

View Set

Test 2- Introduction, Hardware, & Software

View Set

The Portrait of a Lady - Khushwant Singh

View Set