Computer Programming 1 Final

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

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

Addition.java

Java's predefined classes are grouped into

Packages

The empty statement is denoted by what symbol?

Semicolon ;

End-of-line comments that should be ignored by the compiler are denoted using

Two forward slashes ( // ).

What's the proper way to declare an integer array of size 5?

int array = new int[5];

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

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

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 String D. an enumeration constant.

All

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

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

Attribute

A decision symbol in an activity diagram takes the shape of a ________.

Diamond

What data type should be used to represent the following value as numeric? 23.65

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.

Fully Qualified Name

Which of the following will not help prevent infinite loops?

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

What is an Integrated Development Environment (IDE), such as NetBeans or Eclipse?

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

What is output by the following Java code segment? int temp = 180; if (temp > 90) { System.out.println("This porridge is too hot."); // cool down temp = temp - (temp > 150 ? 100 : 20); } else { if (temp < 70) { System.out.println("This porridge is too cold."); // warm up temp = 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

________ models software in terms similar to those that people use to describe real-world objects.

Object-Oriented Design

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

Textbook index

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.

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

Programs remember numbers and other data in the computer's memory and access that data through program elements called

variables.

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.

Which of the following is not one of the three general types of computer languages?

Spoken Languages

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?

\r

Information is passed to a method in ________.

the arguments to the method

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.

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?

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

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

Double

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.

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.

Stacks are known as ________ data structures.

LIFO

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.

Static

What data type should be used to represent the following: "Bob"?

String

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?

Syntax

Which of the following statement displays Hello World?

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

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? 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.

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.

All import declarations must be placed

before the class declaration.

Which of the following data items are arranged from the smallest to the largest in the data hierarchy.

bits, characters, fields, records, files.

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

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

What is a good systematic method for developing a computer program?

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

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.

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

When method printf requires multiple arguments, the arguments are separated with ________.

commas (,)

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

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

Variables should be declared as fields only if ________.

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.

type

The body of each class declaration begins with ________ and ends with ________.

{, }

Which operator can be used in string concatenation?

+=

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.

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

The parameter list in the method header and the arguments in the method call must agree in: Number Type Order

All of the above

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.

All of the above statements are true.

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

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.

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 language programs.

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.

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

Main

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 of the following would not be used to clarify a dangling-else?

Parentheses ()

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.

What is the correct syntax for displaying the message, 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 " );

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 B q = 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: 5 default

The output for Segment A is: 5 default

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 down temp = temp - (temp > 150 ? 100 : 20); } else { if (temp < 70) { System.out.print( "This porridge is too cold! "); // warm up temp = temp + (temp < 50 ? 30 : 20); } } } if (temp == 80) System.out.println("This porridge is just right!");

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

When an object is concatenated with a String, ________.

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


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

Exam #3 BA370 Marketing SDSU Gaffen

View Set

Argumentative Essay Study.com Videos

View Set

Chapter 6: Creating Charts, Diagrams, and Templates

View Set

Interactive Animation: Natural Levee Development with Flooding

View Set

Urinalysis and Other Body Fluids Exam Simulator

View Set

Principles of Management: Disadvantages of Sole Proprietorship

View Set

Chapter 10 Study Guide Introduction to Criminal Justice

View Set