java_ch2_ch3

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

Explain what is meant by the term "conditionally executed"

Conditionally executed code is executed only under a condition, such as an expression being true.

Variable names may begin with a number. True or False?

False

What happens when you compare two String object with the == operator?

The memory addresses of the two String objects are compared.

briefly explain how the print and println methods are related to the system class and the out object

The print and println methods are members of the out object. The out object is a member of the System class. The System class is part of the Java API.

An expression adds a byte variable and a short variable. Of what data type will the result be?

The result will be an int.

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 or False?

True

A variable must be declared before it can be used. True or False?

True

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

True

The value of variable declared with the final keyword can not be changed. True or False?

True

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

braces {}

To create a block of statement, you enclose the statement in these

braces {}

The characters //, /* or /** are used to mark the beginning of a

comment

The if statement is an example of a

decision structure

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

false

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.

false

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

boolean

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

default

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

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

true

When Java converts a lower-ranked value to a higher-ranked type, it is called a

widening conversion

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

&&

how does the character 'A' compare to character 'B'

'A' is less than 'B'

Explain why a misplaced semicolon can cause an if statement to operate incorrectly.

If you inadvertently terminate an if statement with a semicolon, the compiler will assume that you are placing a null statement there. The null statement, which is an empty statement that does nothing, will become the conditionally executed statement. The statement that you intended to be conditionally executed will be disconnected from the if statement and will always execute.

Briefly explain what programming style means. Why should your programming style be consistent?

Programming style refers the way a programmer uses spaces, indentations, blank lines, and punctuation characters to visually arrange a program's source code. An inconsistent programming style can create confusion for a person reading the code.

Assume the file SaleAverage.java is a Java source file that contains documentation comments. Assuming you are in the same folder or directory as the source code file, what command would you enter at the operating system command prompt to generate the HTML documentation files?

javadoc SalesAverage.java

The data 72, 'A', "Hello", 2.17 are examples of

literals

When does a constructor execute? What is its purpose?

A constructor executes automatically when an object is created. Its purpose is to initialize the object's attributes with data and perform any necessary startup operations.

Explain the purpose of a flag variable. Of what data type should a flag variable be?

A flag is a boolean variable that signals when some condition exists in the program. When the flag variable is set to false, it indicates the condition does not yet exist. When the flag variable is set to true, it means the condition does exist.

Describe what the term "self-documenting program" means?

A self-documenting program is written in such a way that you get an understanding of what the program is doing just by reading its code.

What does a variable declaration tell the Java compiler about a variable?

A variable declaration tells the compiler the variable's name and the type of data it will hold.

Why is it good advice to indent all the statement inside a set of braces?

By indenting the conditionally executed statements, you are causing them to stand out visually. This is so you can tell at a glance what part of the program the if statement executes.

What is the difference between comments that start with the // character and comments that start with the /* character?

Comments that start with // are single-line style comments. Everything appearing after the // characters, to the end of the line, is considered a comment. Comments that start with /* are multi-line style comments. Everything between these characters and the next set of */ characters is considered a comment. The comment can span multiple lines.

Briefly describe the difference between variable assignment and variable initialization.

In both cases you are storing a value in a variable. An assignment statement can appear anywhere in a program. An initialization, however, is part of a variable declaration.

What things must be considered when deciding on a data type to use for a variable?

It is important to select a data type that is appropriate for the type of data that your program will work with. Among the things to consider are the largest and smallest possible values that might be stored in the variable, and whether the values will be whole numbers or fractional numbers.

Briefly describe how the && operator works?

It takes two boolean expressions as operands and creates a boolean expression that is true only when both sub expressions are true.

Briefly explain how the || operator works?

It takes two boolean expressions as operands and creates a boolean expression that is true when either of the sub expressions are true.

The class used to display dialog boxes is

JOptionalPane

What is meant my "case-sensitive"? Why is it important for a programmer to know that java is a case-sensitive language?

Java is a case sensitive language, which means that it regards uppercase letters as being entirely different characters than their lowercase counterparts. This is important to know because some words in a Java program must be entirely in lowercase.

Assume that a program uses the named constant PI to represent the value 3.14. The program uses the named constant in several statements. What is the advantage of using the named constant instead of the actual value 3.14 in each statement?

One reason is that the name PI is more meaningful to a human reader than the number 3.14. Another reason is that any time the value that the constant represents needs to be changed, we merely have to change the constant's initialization value. We do not have to search through the program for each statement that uses the value.

This determines whether two different String object contain the same string

The equals method

What risk does a programmer take when not placing a trailing else at the end of an if-else-it statement?

There is no default action that takes place when none of the if clauses' boolean expressions are true.

Why are the relational operators called "relational"?

They determine whether a specific relationship exists between two values. The relationships are greater-than, less-than, equal-to, not equal-to, greater-than or equal-to, and less-than or equal-to.

Why are variable names like x not recommended

You should always choose names for your variables that give an indication of what they are used for. The rather nondescript name, x, gives no clue as to what the variable's purpose is.

The keyword used to declare a constant is

final

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

flag

&&,||, and ! are

logical operators

This is an if statement that appears inside another statement

nested if statement

This key word creates an object

new

The method in Scanner class used to read an integer is

nextDouble

The method in Scanner class used to read a string is

nextLine

This is an empty statement that does nothing

null statement

>,<, and == are

relational operators

Every complete statement ends with a

semicolon

An else clause always goes with

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

The conditional operator takes this many operands

three

The negation operator is

unary


Set pelajaran terkait

6. Name the three serous membranes of the body and describe their general structure.

View Set

CHAPTER 1 people and government 1-2 , 4 essential features of a state 3-6, theories on the origin of the state 7-10 , types of government 11-19, Government according to Aristotle 20

View Set

5 Fundamentals of Electricity: Unit 5 - Resistors

View Set