Ch. 3 APCS

Ace your homework & exams now with Quizwiz!

Translate (x+3)/(2x-7) into Java source code.

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

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

*S*tring

What does Java call constants?

*final* variables

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

/ is for integer *quotient* division % is for integer *remainder* division

What are the 5 *INTEGER* operations?

1) Addition (+) 2) Subtraction (-) 3) Multiplication (*) 4) Integer quotient division (/) 5) Integer remainder division (%)

List the 3 categories of keywords.

1) Reserved words 2) Pre-defined Java identifiers 3) User-defined identifiers

What are the 4 *REAL* number operations?

1) addition (+) 2) subtraction (-) 3) multiplication (*) 4) real number quotient division (/)

List Java's 4 integer types.

1) byte (1 byte) 2) short (2 bytes) 3) int (4 bytes) 4) long (8 bytes)

Translate "one-half" into Java source code.

1.0/2.0 or 0.5

What is "2" + "3"?

23

What is the largest value of a byte?

2^(8-1)-1 = 127

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

3

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

3.3333333333333335 [fifteen 3s after decimal followed by 5]

How many bytes are used by an int?

4 bytes

Translate 7abc into Java source code.

7 (asterisk) a (asterisk) b (asterisk) c

Explain Memory Overflow.

A condition that occurs when the mathematical value is too large to be stored in the actual computer memory space.

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

A reserved word or a predefined identifier

Explain your answer to the previous question (shorts and zip codes)

A short cannot hold any number above 32,767 (2^(7) -1), Many zip codes are larger than this.

What is an escape sequence?

A special set of characters, starting with \, that means something to print, like \n

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

Both

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

Computer memory was scarce and very expensive. Programmers had to do anything they could to save every byte possible.

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

Every variable is assigned the value of Q.

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

George Yuan jk George Boole

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

If the first bit is 0, the number is positive (+). If the first bit is 1, the number is negative (-).

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

It causes a compile error.

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

It prevents confusion to the compiler. (needs some way of telling Java what is literal versus what characters need to be displayed)

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

Memory flow, which alters the sign bit

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

No wtf no, it causes confusion

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?

Overloading

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

The letter is not between double quotes.

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

The second program uses *self-commenting* variables. While, the first program uses *single-letter* variables.

Why does program Java0302.java not compile? //Java0302.java int bruh; int bae; System.out.println(bruh); System.out.println(bae);

There are no values assigned to the variables.

What are the rules for naming an identifier?

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

What is the first Java syntax rule?

Use only keywords known to the Java compiler

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

Yes PEMDAS ayyyyy

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

Yes it is possible No it is not practical

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

\t

What is a self-commenting variable?

a variable whose name describes what the variable is used for

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?

average

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

boolean

What does the escape sequence \n do?

carriage return, line feed (CRLF)

Refer to the previous question. What is the name for this type of shortcut (c1 = c2 = c3 = 'Q';)?

chain assignment

Which data type is used to process individual characters?

char

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

concatenation

Refer to the previous question. Which of these 2 data types is more more accurate?

double

What 2 data types are used by Java for *REAL* numbers?

double and float

What kind of quotes are used with Strings?

double quotes ("word")

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;

Under what condition will the compiler create a bytecode file?

if the source code obeys all Java syntax rules

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

int x = 7;

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

int x;

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

int, double, boolean, String

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

keywords

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?

methods

Would a short be appropriate to store Zip Codes?

nope, it's too *SHORT*

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

primitive [data types]

List 2 examples of Predefined Identifiers

print, println

List 3 examples of Java Reserved Words.

public, static, void

What kind of quotes are used with individual characters?

single quotes ('w')

What is the first form of program documentation?

to use comments

What makes Math, Science, and Computer Science possible?

variables

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

words or compound words

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

x = 7;

What does x %=; mean?

x = x%5 x will become the remainder of dividing x by 5

What does x*=5; mean?

x = x*5 Multiply x by 5

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

x = x+1 In both cases variable x is incremented by 1; the pre/post fix indicates what order of increment or display to do first

What does x+=5; mean?

x = x+5 Increase x by 5

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

x = x-1 In both cases variable x is decremented by 1.

What does x-=5; mean?

x = x-5 Decrease x by 5

What does x /= 5; mean?

x = x/5 Divide x by 5


Related study sets

OB Exam 2: Chapters 18, 20, 21, 22, 23, 24, & 25

View Set

DIFFERENCE BETWEEN TAXATION AND INTEREST RATES

View Set

3305 Client Assessment Lecture PrepU Mastery Level Questions Chapters 11, 16

View Set

PATH CH 24: Fluid and Electrolyte Homeostasis and Imbalances

View Set

Istorija, Murauskienė 02-27 konspektas 1 dalis

View Set

Chapter 5 Search Engine Marketing

View Set