CS120 Midterm

Ace your homework & exams now with Quizwiz!

True or False: A constructor is a method that is automatically called when an object is created.

True

True or False: A file must always be opened before using it and closed when the program is finished using it.

True

True or False: A local variables scope always ends at the closing brace of the block of code in which it is declared.

True

True or False: A parameter variables scope is the method in which the parameter is declared.

True

True or False: A procedure is a set of programming language statements that, together, perform a specific task.

True

True or False: An access specifier indicates how a class may be accessed.

True

True or False: An object can store data.

True

True or 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 or False: Application software refers to programs that make the computer useful to the user.

True

True or False: Constants, variables, and the values of expressions may be passed as arguments to a method.

True

True or False: Each byte is assigned a unique number known as an address.

True

True or False: If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

True

True or False: Instance methods do not have the key word static in their headers.

True

True or False: Java provides a set of simple unary operators designed just for incrementing and decrementing variables.

True

True or False: Logical Errors are mistakes that cause the program to produce erroneous results.

True

True or False: Methods are commonly used to break a problem into smaller manageable pieces.

True

True or False: Named constants are initialized with a value and that value cannot change during execution of program.

True

True or False: Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.

True

True or False: Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

True or False: The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.

True

True or False: The System.out.printf method allows you to format output in a variety of ways.

True

True or False: The System.out.printf method formats a string and displays it in the console window.

True

True or False: The computer is a tool used by so many professionals that it cannot be easily categorized.

True

True or False: The if-else statement will execute one group of statement if its boolean expression is true or another group if its boolean expression is false.

True

True or False: The java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.

True

True or False: The term "no-arg-constructor" is applied to any constructor that does not accept arguments.

True

True or False: The variables scope is the part of the program that has access to that variable.

True

Select all that apply: What of the following steps is normally perform by a for loop?

Update the control variable during each iteration Initialize the control variable to a starting value Terminate when the control variable reaches its max or its min value. Test the control variable by comparing it to a max or a min value.

In java, ______ must be declared before they can be used.

Variables

A _____ type of method performs a task and then terminates it.

Void

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

(( x > 500 && x < 650) || (y != 1000))

Which of the following is correct boolean expression to test for: int x being a value less than or equal to 500 or grates than 650, or int y not equal to 1000?

((x <= 500 || x > 650) && !(y == 1000))

Which symbol indicates that a member is public in a UML diagram?

+

What will be displayed after the following statements are executed? int ans = 10; int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans);

120

What will be displayed after the following statements are executed? int y = 10; if (y==10) { int x = 30; x += y; System.out.println(x); }

40

There are ______ bits in a byte.

8

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y/x);

8.0

Which of the following is a value that is written into the code of a program?

A literal

A runtime error is usually the result of ______.

A logical error

Java requires that the boolean expression being tested by an if statement be enclosed in ______.

A set of parentheses

In the following code, Integer.parseInt(str) is an example of _____. int num; string str = "555"; num = Integer.parseInt(str) + 5;

A value-returning method

The following statement is an example of _____. import java.util.Scanner;

An explicit import statement

True or False" In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

True or False: A java program will not compile unless it contains the correct line numbers.

False

True or False: A method that gets a value from a class's field but does not change it is known as a mutator method.

False

True or False: All it takes for an AND expression to be true is for one of the subexpressions to be true.

False

True or False: Class names and key words are examples of variables.

False

True or False: Colons are used to indicate the end of a java statement.

False

True or False: Compiled byte code is also called source code.

False

True or False: In a for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

False

True or False: In a for loop, the control variable is always incremented.

False

True or False: In the method header the static method modifier means the method is available to code outside the class.

False

True or False: Instance methods should be declared static.

False

True or False: Java Source files end with the .class extension

False

True or False: Java is NOT case sensitive.

False

True or False: Only constants and variables may be passed as arguments to methods.

False

True or False: Programs never need more than one path of execution.

False

True or False: The public access specifier for a field indicates that the field may not be access by statements outside the class.

False

True or False: The while loop is always the best choice in situations where the exact number of iterations is known.

False

True or False: When testing for character values, the switch statement does not test for the case of the character.

False

True or False: When the break statement is encountered in a loop, all the statement in the body of the loop that appear after it are ignored and the loop preps for the next iteration.

False

True or False: When two strings are compared using the String class's compareTo method, the comparison is not case sensitive.

False

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?

FileWriter writer = new FileWriter ("MyFile.txt", true); PrintWriter outFile = new PrintWriter(writer);

A constructor _____.

Has the same name as the class

Select all that apply: Any method that calls a method with a throws clause in its header must _____.

Have the same throws clause Handle the potential exception

If a loop does not contain, within itself, a valid way to terminate, it is called an ______.

Infinite loop

Another term for an object of a class is an _____.

Instance

Each repetition of a loop is known as an ______.

Iteration

When an argument is passed to a method _____.

Its value is copied into the methods parameter variable.

The original name for java was ______.

Oak

An ______ is a software entity that contains data and procedures.

Object

Most of the programing languages used today are _____.

Object-oriented

A special variable that holds a value being passed into a method is called a _____.

Parameter

A constructor is a method that _____.

Performs initialization or setup operations

Select all that apply: Which of the following are classes from the java API?

PrintWriter

Select all that apply: Which of the following are benefits of using methods in programming?

Problem are solved more easily. Programs are simplified. Code can be reused.

A ______ is used to write computer programs.

Programming Language

One type of design tool used by programmers when creating a model of a program is ______.

Psuedocode

Which of the following statements will create an object from the Random class?

Random myNumber = new Random();

______ operators are used to determine whether a specific relationship exists between two values.

Relational

To print "Hello, world" on the monitor, which of the following java statements should be used?

System.out.println("Hello, world");

The primitive data types only allow a ______ to hold a single value.

variable

Which of the following types of values can be passed to a method that has an int parameter visible?

int

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7; displayValue(x);

Which of the following expressions will generate a random number in the range of 1 through 10?

myNumber = randomNumbers.nextInt(10) + 1;

Select all that apply: Which method of the Random class will return a random number within the range of 0.0 and 1.0?

nextFloat() nextDouble()

Character literals are enclosed in ______ and string literals are enclosed in ______.

single quotes, double quotes

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

str1.equalsIgnoreCase(str2)

Which of the following is not a primitive data type?

string

What will be the value of x after the following code is executed? int x - 10, y = 20; while (y < 100) { x += y; }

this is an infinite loop

A flag may have the values ______.

true or false

Which of the following is the not equal operator?

!=

What will be the value or discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = 0.08; break; case 'B': discountRate = 0.06; case 'C': discountRate = 0.04; default: discountRate = 0.0;

0.0

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales <7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

1000

What is the value of charges after the following code has been executed? double charges, rate 7.00; int time = 180; charges = time <= 119 ? rate * 2 : time / 60.0 * rate;

21.00

What will be the value of pay after the following statements are executed? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) * payRate * 1.5;

475.00

What is the result of the following expression: 10+5*3-20

5

Because java byte code is the same on all computers, compiled java programs ______.

Are highly portable.

Values stored in local variables _____.

Are lost between calls to the method in which they are declared.

Which of the following is NOT one of the major components of a typical computer system?

CPU, Input/Output Devices, Main Memory, & Secondary Storage. (ALL OF THESE are major components)

A characteristic of ______ is that only an objects methods are able to directly access and make changes to an objects data.

Data hiding

Variables are classified according to their ______.

Data types

Which of the following is NOT part of the programming process?

Defining & modeling the problem, Entering code & compiling it, and testing and debugging. (ALL OF THESE)

To create a method, you must write its _____.

Definition

An item that separates items is known as a ______.

Delimiter

Which of the following would contain the translated java byte code for a program named Demo?

Demo.class

You should always document a method by writing comments that appear _____.

Just before the methods definition

Which of the following cannot be used as identifiers in java?

Key words

Select all that apply: Local variables _____.

Lose the values stored in them between calls to the method in which the variable is declared. May have the same name as local variables in other methods. Are hidden from other methods.

Each different type of CPU has its own ________.

Machine Language

A reference variable store a _____.

Memory address

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

Methods

What will be displayed as a result of executing the following code? public class test { public static void main (String[] args) { int value1 = 9; System.out.println(value1); int value2 = 45; System.out.println(value2); System.out.print(value3); value = 16; } }

Nothing, this is an error.

Which of the following statements corrects creates a Scanner object for keyboard input?

Scanner keyboard = new Scanner(System.in);

The end of a java statement is indicated by a ______.

Semicolon

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

String

Which of the following is NOT involved in identifying the classes to be used when developing an object-oriented application?

The code

The scope of a private instance field is _____.

The instance methods of the same class

A parameter variables scope is _____.

The method in which the parameter is declared.

When you pass an argument to a method you should be sure that the arguments type is compatible with _____.

The parameter variables data type

What is Syntax?

The rules that just be followed when writing a program.

If the following java statements are executed, what will be displayed? System.out..println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");

The top three winner are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

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

The z field is available to code written outside the Sphere class.

Two or more methods in a class may have the same name as long as _____.

They have different parameter lists

A value returning method can return a reference to a non-primitive type.

True

True or 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 or False: Two general categories of methods are void methods and value returning methods.

True

True or False: Unicode is an international encoding system that is extensive enough to represent all the characters of all the worlds alphabets.

True

True or False: When an object is passed as an argument to a method, the objects address is passed into the methods parameter variable.

True

True or 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 or False: When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.

True

True or False: When you open a file with the PrintWriter class, the class can potentially throw an IOException.

True

True or False: When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same named will be created.

True

True or False: Without programmers, the users of computers would have no software and without software, computers would not be able to do anything.

True

True or False: You must have a return statement in a value-returning method.

True

Which of the following are pre test loops?

While, for

To display the output on the next line, you can use the println method or use the ______ escape sequence in the print method.

\n

What will be the values of ans, x and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x = 0, y = 50

A _____ can be thought of as a blueprint that can be used to create a type of _____.

class, object

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter ("DiskFile.txt");

diskOut.println("Calvin");

Given the following method header, which of these method calls is incorrect? public void displayValue(int x, int y) { ..... }

displayValue(a, b); // where a is short and b is long

Which of the following will run the compiled program called ReadIt?

java ReadIt

Which of the following will compile a program called ReadIt?

javac ReadIt.java

Which is a control structure that causes a statement or group of statements to repeat?

loop

A ______ is a value that signals when the end of a list of values has been reached.

sentinel

In an if-else statement, if the boolean expression is false then ______.

the statement or block following the else is executed.

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

while (inputFile.hasNext())


Related study sets

Juvenile Justice Exam #1 Chapter 2: The History and Philosophy Behind the Juvenile Justice System Study Set

View Set

Capsim TQM/Sustainability Quiz--Business Policy (Williamson)

View Set

LAN and WAN, Cisco Routing and Switching Pro Chapter 4, CCNA2 LS CH9, CCNA, Practice Exam 1

View Set

Chapter 5: River Systems and Groundwater Resources

View Set