Computer Science - Chapter 3 Test

Ace your homework & exams now with Quizwiz!

Under what condition will the compiler create a bytecode file?

If the source code obeys all the Java syntax rules, then the compiler will create a bytecode file.

What is an escape sequence?

An escape sequence is a single slash followed by some character placed between double quotes.

Name another Java syntax rule.

Another syntax rule is that each variable needs to specify its data type.

Who invented a form of Algebra based on logical statements that are either true or false?

George Boole invented a form of Algebra based on logical statements that are either true or false.

Java Integer Mathematics: 5 / 6

0 ( won't put decimal, so its just zero, you need to type cast a "double" to get the decimal )

Translate "one half" into Java source code.

1/2

What is the largest value of a byte?

127

Unary operators can be used with ______________ or ___________ style.

- postfix, prefix

The age of single-letter variables is gone. Variables should now be __________________ or _______________________________.

- words - compound words

What is "2" + "3" ?

"2" + "3" is twenty three.

Translate 𝕩 + 𝟛/𝟚𝕩 - 𝟟 into Java source code.

( x + 3 ) / ( 2*x - 7 )

What is the output of: System.out.println( 10 / 3 ); ?

3 is the output.

How many bytes are used by an int?

4 bytes

Translate 7abc into Java source code.

7*a*b*c

A computer program is made up of words, which usually are called what?

A computer program is made up of Keywords.

What is a self-commenting variable?

A self-commenting variable is a variable whose name describes what the variable is used for.

Why were computer programs in the 1960s and the 1970s often written with single-letter variables?

Computer programs in the 1960s and the 1970s were often written with single-letter variables because computer memory was scarce and expensive.

What are the Real Number Types?

Double and Float

What kind of quotes are used with strings?

Double quotes are used with strings.

Why do we need escape sequences to generate backslash ( \ ) and quote ( " ) characters?

Escape sequences prevent confusions to the compiler.

When you are creating User-Defined Identifiers, you must make sure your identifier is not one of what two things?

Individuals must make sure their identifier is not a reserved word or a predefined word.

Why does program Var02.java not compile?

It does not compile because the variables are unassigned.

What does Java call constants?

Java calls constants final variables because their value can not be changed.

Does Java follow the same Order of Operations that you learned in your Math class?

Java does follow the order of operations.

Should Java shortcuts be combined with other Java statements? Example: System.out.println(x++);

Java short cuts should never be combined. It causes confusion.

What is Java's formal language for the term simple data types?

Java's formal language for the term simple data types is primitive.

List Java's 4 integer types.

Java's four integer types are byte, short, int, and long.

Look at programs Document01.java and Document02.java. Both programs do the exact same thing. Why is the second program so much easier to understand?

Java0318.java is easier to understand because the variables are self-commenting.

Explain Memory Overflow.

Memory Overflow is when a variable exceeds the given storage space, depending on data type. This can change a positive to a negative or a negative to a positive.

In a well-documented program, are single-line comments or multi-line comments necessary in a program that already uses good self-commenting variables?

No comments are necessary when the variables are self-commenting.

What is the first Java syntax rule?

Only keywords known to the Java compiler can be used in a program is the first Java syntax rule.

Is real number remainder division possible in Java? If so is it practical?

Real number remainder division is possible in Java, however it is not practical.

What kind of quotes are used with individual characters?

Single quotes are used with individual characters.

How is it possible for a computer to multiply 2 positive numbers, and get a negative product?

The computer multiples two positive numbers, and gets a negative product because of a computer error that is specifically caused by Memory Overflow.

Which data type is used to process sets of one or more characters?

The data type "String" is used to process sets of one or more characters.

Which data type is used to process individual characters?

The data type "char" is used to process individual characters.

What is the difference between the / and the % division operators?

The difference between Integer Quotient Division and Integer Remainder Division is that Integer Quotient Division shows how many times a number can evenly go into another number, but Integer Remainder Division shows the remainder of a division between two numbers

What is the fancy name for using the plus ( + ) sign to join strings together?

The fancy name for using the plus ( + ) sign to join strings together is concatenation.

What is the first form of program documentation?

The first form of program documentation is to use comments.

What are the 5 integer operations?

The five integer operation are addition ( + ), subtraction ( - ), multiplication ( * ), integer quotient division ( / ), and integer remainder division ( % ).

What are the 4 data types that will be tested on the AP Exam?

The four data types that will be tested on the AP Exam are int, double, boolean and String

What are the 4 real number operations?

The four real number operations are addition, subtraction, multiplication, and real number quotient division

In program Var01.java, why does the statement: System.out.println(a); display the value of 10 and not a?

The letter is not in double quotes

Explain your answer to the previous question. Previous question: ( Would a short be appropriate to store Zip Codes? ) Answer to previous question: nope, its too *SHORT*

The maximum value in a short is 32,767, some zip codes can exceed this value, causing a memory overflow.

Java has a large number of libraries that enhance the basic Java language. These libraries contain special program modules that perform a variety of tasks to simplify the life of a programmer. What are these modules called?

The modules are called methods.

Refer to the previous question. What is the name for this type of short cut? Previous Question : In program Text01.java, what is accomplished by the statement: c1 = c2 = c3 = 'Q'; ?

The name of the shortcut is chain assignment (chaining).

What is the output of: System.out.println( (double) 10 / 3 ); ?

The output is 3.333333

What happens when you attempt to alter the value of a constant?

The program will not longer compile.

In program Text01.java, what is accomplished by the statement: c1 = c2 = c3 = 'Q'; ?

The statement assigns each variable the value of 'Q'.

Print the Java statement that will declare x as an integer and assign the value of 7 to x in one single statement.

The statement is, int x = 7

Print the Java statement that will declare x as an integer.

The statement is, int x.

Print the statement that will assign the value of 7 to x.

The statement is, x = 7

List the 3 categories of keywords.

The three categories of keywords are Reserved words, Pre-defined Java Identifiers, and User-defined Identifiers

Suppose you are writing a program to compute the average of a list of numbers. What name should you give the variable that stores the average?

The variable should be given the name average, so that its purpose can be identified easily.

List 3 examples of Java Reserved Words.

Three examples of Java Reserved Words are public, static, and void.

What 2 data types are used by Java use for real numbers?

Two data types that are used by Java for real numbers are float and double.

List 2 examples of Predefined Identifiers.

Two examples of Predefined Identifiers are Print and println

What are the rules for naming an identifier?

Use alpha-numeric characters and start with an alpha character.

What makes Math, Science and Computer Science possible?

Variables make Math, Science and Computer Science possible.

The plus ( + ) sign can be used to add integers and real numbers. It can also be used to join strings. What is it called when one operator can perform different functions.

When more than one operator can perform different functions than it is called overload.

What does x %= 5; mean?

X %= 5; means to find the remainder of x divided by five, but not include the decimal.

What does x -= 5; mean?

X is being decreased by five.

What does x /= 5; mean?

X is being divided by five.

What does x += 5; mean?

X is being increased by five.

What does x *= 5; mean?

X is being multiplied by five.

In binary, what indicates if a number is positive or negative?

Zero ( 0 ) indicates a positive and one ( 1 ) indicates a negative. The first bit is 0, the number is positive and if the first bit is 1, then the number is negative.

What does the escape sequence \n do?

\n makes a carriage return, line feed.

What escape sequence is used to generate a <tab>?

\t is used to generate a tab.

An LValue is . . .

a memory address that assigns a value to a variable. A memory location.

The short cuts ++k; or k++; means . . .

add one to the value of k

An equal sign is . . .

an assignment operator

Today, in computer science, a data type that has only two values of true and false is a called a _________________________________ data type.

boolean

What are the Java int data types from smallest to largest?

byte, short, int, long

Each reserved word has a special meaning to Java and these reserved words _________________ be used as an identifier, or variable name, for any other purpose in a program

cannot

Refer to the previous questions. Which of these is more accurate? Previous Question: What 2 data types are used by Java use for real numbers?

double

Java allocates _________ bytes of memory for its largest real number data type.

eight

Say you want to use the mathematical value of E (another non-repeating decimal similar to PI) in your program with value of 2.718281828. This value will never change in your program. Print the proper way to define and initialize this constant.

final double E = 2.718281828;

Would a short be appropriate to store Zip Codes?

nope, it's too *SHORT*

What is are Java Unary operators?

operators with a single operand

Name two Java methods. Are they predefined identifiers?

print and println; yes

An RValue is . . .

stored in the memory address of an LValue.

The short cuts k--; or --k; means . . .

subtract one from the value of k

When making a user-defined variable, you must make sure . . .

that the identifier starts with an alpha character.

What is an operand?

the quantity on which an operation is to be done.

A compiler will only compile and create bytecode when . . .

the source code obeys all the Java syntax rules.

What does x++; or ++x; mean?

x++; and ++x; both add one to x.

What does x--; or --x; mean?

x--; and --x; both subtract one from x.


Related study sets

Psychological testing and assessment exam 2

View Set

Abdominal Sonography CTL: Pathology 42% Part 1,2

View Set

Series 6 : Investment Company Products and Regulation (Lesson 2 Practice Questions)

View Set

Prin. of Management - Ch 11 & 12

View Set

Ch.1: Concepts of Health and Disease

View Set