Midterm Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

the negation operator is

unary

In Java, when a character is stored in memory, it is actually the ______ that is stored

unicode

A flag may have the values

True or False

The named storage location in the computer memory

Variable

The primitive data types only allow a(n) ________ to hold a single value.

Variable

Key words are____

Words that have a special meaning in the programming language

Why should you be careful when choosing a sentinel value?

You should be careful not to use a value that can be mistaken for a valid input

If you were to look at a machine language program, you would see .

a stream of binary numbers

This is a variable that keeps a running total.

accumulator

Each byte is assigned a unique

address

When a program is finished using a file, it should do this.

close the file

When determining whether a number is inside a range, it's best to use this operator.

&&

These character mark the beginning of a multiline comment

/*

These character mark the beginning of a documentation comment

/**

These character mark the beginning of a single line comment

//

Which of the following are not valid println statements? (Indicate all that apply.) System.out.println + "Hello World"; System.out.println("Have a nice day"); out.System.println(value); println.out(Programming is great fun);

1,3,4

What will the value of x be after the following statements are executed int x = 75; int y = 60; if (x>y) x = x-y

15

What will the value of x be after the following statements execute? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x += 3

20

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

45,678.26

What will the println statement in the following program segment display? int x = 5; System.out.println(x++);

5

What will the println statement in the following program segment display? int x = 5; System.out.println(++x);

6

What is the result of the following expression 17 % 3 * 2 - 12 + 15

7

Which of the following are not valid assignment statements? (Indicate all that apply.) total = 9; 72 = amount; profit = 129 letter = 'W';

72 = amount, numbers cannot be first

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

A program must have at least one of the following

A class definition

How does the character 'A' compare to the character 'B'?

A is less than B

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

A set of parentheses

Which of the following is a named storage location in the computers memory a literal a variable a constant an operator

A variable

RAM is usually______

A volatile types of memory, used for temporary storage

Assume x is a double variable, and rand references a Random object. What does the following statement do? x = rand.nextDouble();

Assigns a random number in range of 0.0 to 1.0 to the x variable

This type of expression has a value of either true or false

Boolean expression

A group of statements, such as the contents of a class or a method, are enclosed in

Braces

Which part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information?

CPU

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

Demo.class

Comments that begin with // can be processed by javadoc.

False

Java files end with the .class extension

False

Java is not case sensitive.

False

The = operator and the == operator perform the same operation.

False

The contents of a variable cannot be changed while the program is running.

False

Variable names may begin with a number.

False

When testing for character values, the Switch statement does not test for the case of the character

False

To open a file for reading, you use the following classes.

File and Scanner

What classes do you use to read data from a file?

File and Scanner

_____ refers to the physical components that a computer is made of

Hardware

Which of the following is not a rule that must be followed when naming identifiers The 1st character must be one of the letters A/a-Z/z, underscore, or a $ Identifiers can contain spaces Upper/lowercase characters are distinct After the 1st character, you can use the letters A/a-Z/z, underscore, 0-9, or a $

Identifiers can contain spaces

Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt(100);

It assigns the variable x a random integer in the range 0 through 99.

Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt(9) + 1;

It assigns the variable x a random integer in the range 1 through 9.

Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt();

It assigns the variable x a random integer in the range −2,147,483,648 to 2,147,483,647

You can use this class to display dialog boxes.

JOptionPane

JVM stands for

Java Virtual Machine

What would be printed out as a result of the following code? System.out.println ("the quick brown fox" + "jumped over the \n" "slow moving hen.");

Nothing, there is an error

What will be displayed as a result of executing the following code? Final int = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y)

Nothing, there is an error in the code

These are symbols or words that perform operations on one or more operands.

Operators

This class allows you to use the print and println methods to write data to a file.

PrintWriter

To open a file for writing, you use the following class.

PrintWriter

What class do you use to write data to a file?

PrintWriter

The two primary methods of programming in use today are_____

Procedural and Object oriented

These are words or names that are used to identify storage locations in memory and parts of the program that are created by the programmer.

Programmer defined names

A cross between human language and programming language is called _____

Pseudocode

What is a syntax?

Rules that must be followed when writing a program

This class allows you to read a line from a file.

Scanner

Which of the following correctly creates a Scanner object for keyboard input Scanner keyboard = new Scanner(System.in); Keyboard scanner = new Keyboard(System.in); Scanner kbd = new Scanner(System.keyboard); Scanner keyboard(System.in);

Scanner keyboard = new Scnnaer(System.in);

This type of memory can hold data for long periods of time—even when there is no power to the computer.

Secondary Storage

________ works like this, If the expression on the left side of the && operator is false, the expression on the right side will not be checked

Short-circuit evaluation

Java was developed by _____

Sun Microsystems

Variables are

Symbolic names made up by the programmer that represents locations in the computer's RAM

These are the rules that must be followed when writing a program.

Syntax

You can use this method to display formatted output in a console window.

System.out.printf

The CPU (Central Processing Unit) consists of two parts which are _____

The Control Unit and the Logic Unit

This determines whether two different String objects contain the same string.

The equals method

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

The statement or block following the else is executed

The conditional operator takes this many operands.

Three

A conditionally executed statement should be indented one level from the if clause.

True

A left brace in a Java program is always followed by a right brace later in the program.

True

A local variables scope always ends at the closing brace of the block of code in which it is declared

True

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

True

A variable may be defined in the initialization expression of the for loop.

True

A variable must be declared before it can be used.

True

A variable's scope is the part of the program that has access to the variable.

True

All it takes for an OR expression to be true is for one of the subexpressions to be true.

True

All lines in a conditionally executed block should be indented one level.

True

Application software refers to programs that make the computer useful to the user

True

In a nested loop, the inner loop goes through all of its iterations for every iteration of the outer loop.

True

In a switch statement, each of the case values must be unique

True

Logical errors are mistakes that cause the program to produce erroneous results.

True

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

True

The Java API provides a class method named Math that contains numerous methods which are useful for performing complex mathematical operations

True

The scope of a variable is limited to the block in which it is defined.

True

The system.out.printf method formats a string and displays it in the console window

True

To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.

True

Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.

True

When an if statement is nested in the else clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

True

When an if statement is nested in the if clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

True

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

True

What will the values of ans ,x, and y be 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 byte is made up of eight

bits

A block of code in enclosed in a set of

braces

To create a block of statements, you enclose the statements in these.

braces

The java compiler generates

byte code

This type of operator lets you manually convert a value, even if it means that a narrowing conversion will take place.

cast

Which of the following determines whether the char variable, CharA, is not equal to the letter 'A' chrA != 'A' chrA== 'A' chrA.notEquals(A) chrA || 'A'

chrA != 'A'

What is the difference between an input file and an output file?

data is read from input file and written to an output file

The if statement is an example of a

decision structure

This section of a switch statement is branched to if none of the case expressions match the switch expression.

default

This type of loop always executes at least once.

do-while

Which of the following statements is invalid double r = 2.9X106 double r = 9.4632E15 double r = 326.75 double r = 9.4632e15

double r = 2.9X106

Both characters and string literals can be assigned to a char variable

false

If one of an operator's operands is a double, and the other operand is an int, Java will automatically convert the value of the double to an int.

false

It is not necessary to initialize accumulator variables.

false

One limitation of the for loop is that only one variable may be initialized in the initialization expression.

false

The Do-While loop is a pretest loop

false

The For loop is a posttest loop

false

This keyword is used to declare a named constant

final

This is a boolean variable that signals when some condition exists in the program.

flag

Which of the following is valid? float y; double z; z = 934.21; y = z; float w; w = 1.0f; float y; y = 54.9; float v; v = 1.0

float w; w = 1.0f;

Which of the following statements determines whether the variable temp is within the range of 0-100 (inclusive) if (temp > 0 || temp < 100) if (temp > 0 && temp < 100) if (temp >= 0 && temp =< 100) if (temp >= 0 || temp =< 100)

if (temp >= 0 && temp =< 100)

What import statement will you need in a program that performs file operations?

import java.io.*

This type of loop has no way of ending and repeats until the program is interrupted.

infinite

This expression is executed by the for loop only once, regardless of the number of iterations.

initialization expression

What is the three expressions that appear in the parentheses in a for loop's header

initialization, test, and update

What is each repetition of a loop known as?

iteration

Which of the following will run the compiled program called ReadIt run ReadIt java ReadIt go ReadIt java ReadIt.java

java ReadIt

To compile a program named First you would use which of the following commands? compile First.java javac First.java java First.java javac First

javac First.java

Which of the following will compile a program called ReadIt java ReadIt.javac javac ReadIt.javac javac ReadIt.java java ReadIt.java

javac ReadIt.java

These are words that have a special meaning in the programming language.

key words

The following data are examples of what 72 'A' "Hello World" 2.8712

literals

&&, ||, and ! are

logical operators

This is a variable that controls the number of iterations performed by a loop.

loop control variable

This is an if statement that appears inside another if statement.

nested if statement

Which Scanner class method would you use to read a double as input?

nextDouble

Which Scanner class method would you use to read a string as input?

nextLine

This is an empty statement that does nothing.

null statement

In the expression number++, the ++ operator is in what mode?

postfix

The do-while loop is this type of loop.

posttest

The for loop is this type of loop.

pretest

The while loop is this type of loop.

pretest

Software refers to ____

programs

Application software refers to _____

programs that make the computer useful to the user

These characters serve specific purposes, such as marking the beginning or ending of a statement, or separating items in a list.

punctuation

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

relational

>,<, and == are

relational operators

Every complete statement ends with a

semicolon

This is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.

sentinel

Characters literals are enclosed in ____ and string literals are enclosed in _____

single quotes and double quotes

If str1 and str2 are both String object, which of the following expressions will correctly determine whether or not they are equal str1 += str2 str1 = str2 str1.equals(str2) str1 && str2

str1.equals(str2)

When the + operator is used with strings, it is known as the

string concatenation operator

An else clause always goes with .

the closest previous if clause that doesn't already have its own else clause

What clause must you write in the header of a method that performs a file operation?

throws IOException

The While loop is a pretest loop

true

When Java converts a lower-ranked value to a higher-ranked type, it is called a(n) .

widening conversion

In the following program segment, which variable is the loop control variable (also known as the counter variable) and which is the accumulator? int a, x = 0, y = 0; while (x < 10) { a = x * 2; y += a; x++; } System.out.println("The sum is " + y);

x is the loop control and y is the accumulator


Set pelajaran terkait

Pénzügyi és Biztosítási piac szereplői

View Set

CH 5 cultural awareness and health practices

View Set

Mastering Biology for test 2 + Clicker

View Set

CSCI361 Operating Systems Chapter 5

View Set

Business Statistics (True/False) II

View Set

biology test 3: the endocrine system

View Set