Java Final

Ace your homework & exams now with Quizwiz!

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

(str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)

In UML diagrams, this symbol indicates that a member is public.

+

In UML diagrams, this symbol indicates that a member is private.

-

How many times will the following do-while loop be executed? int x = 11; do { x += 20 } while (x > 100);

1

A for loop normally performs which of these steps?

1) Initializes a control variable to a starting value 2) Tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value 3) Updates the control variable during each iteration

What is the value of and after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x < y) ans += y;

100

What is the value of x after the following code has been executed? int x = 75; int y = 90; if { x != y } x += y;

165

What will be printed when the following code is executed? double x = 45678.259; System,.out.printf("%,.2f", x);

45,678.3

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100);

5

Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, { double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public double finalOrderTotal() { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder { public static void main(String[] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(orderNumber, orderAmt, orderDisc); double finalAmount = order.finalOrderTotal(); System.out.println("Final order amount = $" + } } finalAmount); } }

522.00

What does the following code display? int d = 9, e = 12; System.out.printf("%d %d/n", d, e);

9 12

RAM is usually:

A volatile type of memory, used only for temporary storage

In Java, it is possible to write a method that will return:

A whole number, a monetary value, a string of characters, a reference to an object

Look at the following statement. import java.util.*; This is an example of:

A wildcard import

Look at the following statement. important java.util.Scanner; This is an example of:

An explicit import

Each repetition of a loop is known as what?

An iteration

Because Java byte code is the same on all computers, compiled Java programs:

Are highly portable.

All Java statements end with semicolons.

False

TRUE/FALSE: A method that gets a value from a class's field but does not changed it is known as a mutator method.

False

TRUE/FALSE: Assuming that pay has been declared a double, the following statement is valid. pay = 2,538.44;

False

TRUE/FALSE: Both character literals and string literals can be assigned to a char variable.

False

TRUE/FALSE: Class names and key words are examples of variables.

False

TRUE/FALSE: If a class has a method name finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

False

TRUE/FALSE: In Java the variable named total is the same as the variable named Total.

False

TRUE/FALSE: In the method header the static method modifier means the method is available to code outside the class.

False

TRUE/FALSE: In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

TRUE/FALSE: Instance methods should be declared static.

False

TRUE/FALSE: Java is a case-insensitive language.

False

TRUE/FALSE: Only constants and variables may be passed as arguments to methods.

False

TRUE/FALSE: The do-while loop is a pre-test loop.

False

TRUE/FALSE: The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

TRUE/FALSE: The this key word is the name of a reference variable that is available to all static methods.

False

TRUE/FALSE: When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

False

TRUE/FALSE: You can declare an enumerated data type inside of a method.

False

A constructor:

Has the same name as the class

Another term for an object of a class is:

Instance

Each different type of CPU has its own:

Machine language

Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must:

Make sure you are in the same directory or folder where MyClass.java is located

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

Methods

The switch statement is a:

Multiple alternative decision structure

What is the value of and after the following code has been executed? int x = 40; int y = 40; int ans = 0; if (x = y) ans = x + 10;

No value, this is a syntax error.

Enumerated types have this method, which returns the position of an enum constant in the declaration list.

Ordinal

Byte code instructions are:

Read and interpreted by the JVM

This type of operator determines whether a specific relationship exists between two values:

Relational

Syntax is:

Rules that must be followed when writing a program

Another term for programs is:

Software

An object's _____ is simply the data that is stored in the object's field at any given moment.

State

Instance methods do not have this keyword in their headers:

Static

Static methods can only operate on ________ fields.

Static

Java allows you to create objects of this class in the same way you would create primitive variables.

String

The major components of a typical computer system consist of

The CPU, Input/output devices, Main memory, Secondary storage devices

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account);

The account object's toString method will be implicit called.

If you attempt to preform an operation with a null reference variable:

The program will terminate.

Application software refers to:

The programs that make the computer useful to the user

In a UML diagram to indicate the data type of a variable enter:

The variable name followed by a colon and the data type.

Given the following code, what will be the value of finalAmount when is is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order (int orderNumber, double orgderamt, double orderDisc) { orderNumber = orderNumber; orderAmount = orderAmt; order Discount = orderDisc; } public int getOrder

There is no value because the object order has not been created.

If the following is from the method section of a UML diagram, which of the following statements is true? + add(object2:Stock) : Stock

This is a public method named add that accepts and returns references to objects in the Stock class.

If the following is from the method section of a UML diagram, which of the following statements is true? + equals(object2:Stock) : boolean

This is a public method that accepts a Stock object as its argument and returns a boolean value.

The purpose of validating the results of the program is:

To determine whether the program solves the original problem.

TRUE/FALSE: A class's static methods do not operate on the fields that belong to any instance of the class.

True

TRUE/FALSE: A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.

True

TRUE/FALSE: A single copy of a class's static field is shared by all instances of the class.

True

TRUE/FALSE: A variable's scope is the part of the program that has access to the variable.

True

TRUE/FALSE: An access specific indicates how the class may be accessed.

True

TRUE/FALSE: An enumerated data type is actually a special type of class.

True

TRUE/FALSE: An instance of a class does not have to exist in order for values to be stored in a class's static fields.

True

TRUE/FALSE: An object can store data.

True

TRUE/FALSE: Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.

True

TRUE/FALSE: Both instance fields and instance methods are associated with a specific instance of a class, and they connoted be used until an instance of the class is created.

True

TRUE/FALSE: Constants, variables, and the values of expressions may be passed as arguments to a method.

True

TRUE/FALSE: If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

True

TRUE/FALSE: If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

True

TRUE/FALSE: If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

True

TRUE/FALSE: If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());

True

TRUE/FALSE: Instance methods do not have the key word static in their headers.

True

TRUE/FALSE: Methods are commonly used to break a problem into small manageable pieces.

True

TRUE/FALSE: Named constants are initialized with a value, that value cannot be changed during the execution of the program.

True

TRUE/FALSE: No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

TRUE/FALSE: Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.

True

TRUE/FALSE: The expression in a return statement can be any expression that has a value.

True

TRUE/FALSE: The key word this is is the name of a reference variable that an object can use to refer to itself.

True

TRUE/FALSE: The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.

True

TRUE/FALSE: Two general categories of methods are void methods and value returning methods.

True

TRUE/FALSE: When an object is passed as an argument, it is actually a reference to the object that is passed.

True

TRUE/FALSE: When an object reference is passed to a method, the method may change the values in the object.

True

TRUE/FALSE: When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

True

TRUE/FALSE: When you open a file with the PrintWriter class, the class can potentially throw an IOException.

True

TRUE/FALSE: You must have a return statement in a value-returning method.

True

TRUE/FALSE: enum constants have a toString method.

True

A Boolean expression is one that is either:

True or False

Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by:

Using the private access specific on the class fields.

If object1 and object2 are objects of the same class, to make object2 a copy of object1:

Write a copy method that will make a field by field copy of object1 data members into object2 data members.

After the header, the body of the method appears inside a set of:

braces, { }

In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _______; the middle section holds _______; the bottom section holds _______.

class name; attributes or field; methods

In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.

class; objects

It is common practice in object-oriented programming to make all of a class's:

fields private

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext()) { ... }

What will be printed when the following code is executed? int y = 10; if (y == 10) { int x = 30; x+= y; } System.out.print("x = "); System.out.print(x);

x is unknown when the last statement is executed.

For the following code, which statement is NOT true? public class Circle { private double radius; public double x; private double y; }

y is available to code that is written outside the Circle class.

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }

z is available to code that is written outside the Sphere class.


Related study sets

TMS NTI (New Testament Introduction) Dr. Osborne Final Exam

View Set

AZ-900 Practice Exam Revamped Lets see if this works

View Set

9th Grade Honors Biology Unit 1 Characteristics of life

View Set

Google Analytics Academy: Beginners - Assessment 2

View Set

Chapter 18 Multiple Choice- Conceptual

View Set

CH 19 Administration of Medication

View Set

020 - Chapter 20 - Praxis 5039 (Chapter Test)

View Set

APES: Greatest Good & Tragedy of the Commons

View Set

Intro to Fitness Management Ch 9

View Set

PADI Open Water - Being a Diver I

View Set