Chapter 4: Fundamental Data Types Flashcards
How many primitive types are in java?
8
How many integer types are there?
4
How many floating-point types in java?
2
What is Integer.MAX_Value?
2.14 billion
What is Integer.MIN_VALUE
-2.14 billion
What is a number literal?
any number in a java program
What happens when a numeric computation overflows?
the result falls outside the range for the number type
T/F There is a warning when a numeric computation overflows?
False
What is the simplest remedy for numeric computation overflows?
Use the long type
T/F: It is legal to assign an integer type to a floating-point variable
true
When does a rounding error occur?
when an exact representation of a floating-point number is not possible
T/F: it is legal to assign a double value to an int value?
false - it is an assignment error
What are numerical constants?
values that do not change and have special significance for a computation
What happens when you tag a variable final?
You can never change after it has been set
What do many programmers name constants?
All upper case, separating words with underscores
How are constants declared?
public
What is an expression
The combination of variables, literals, and/or method calls
What does integers and floating-point values in an arithmetic expression yield?
a floating-point value
What does the ++ operator do?
adds 1 to a variable
What does the – operator do?
subtracts 1 from a variable
If both arguments are integers, and the mathematical result is a floating-point number, what happens to the remainder?
It is discarded
What does the modulus operator compute?
the remainder of an integer division
What is the modulus operator?
%
How do you take the square root of a number?
Math.sqrt(x)
How do you take a number to the power?
Math.pow(x, y)
How do you take the sin of a number?
Math.sin(x)
How do you take the cosine of a number?
Math.cos(x)
How do you take the tangent of a number?
Math.tan(x)
How do you find the closest integer to x?
Math.round(x)
How do you find the smallest integer greater than x
Math.ceil(x)
How do you convert degrees to radians?
Math.toRadians(x)
How do you take the absolute value of a number
Math.abs(x)
How do you find the larger of two numbers
Math.max(x, y)
How do you find the smaller of two numbers
Math.min(x, y)
How do you find e to the power of x
Math.exp(x)
How do you find the log of x, given that x is greater than 0?
Math.log(x)
How do you find the decimal log of x?
Math.log10(x)
How do you find the largest int that is less than x
Math.floor(x)
How do you convert radians to degrees?
Math.toDegrees(x)
How do you convert a value to a different type?
use a cast(typeName)
What does text consist of?
characters
What are characters?
letters, numbers, punctuations, spaces, and so on
What is a string?
a sequence of characters
What does a string literal do?
denote a particular string
What does it mean to concatenate two strings?
to combine two strings into one large string
What operator do you use to concatenate strings?
+
Can you concatenate a int?
Yes - as long as one of the arguments of the + operator is a string
How do you include a quotation mark in a literal string
A backslash ()
e.x.:
“He said "Hello"”
What is this sequence called: "
escape sequence
How do you use a backslash in a string
Use this escape sequence: \
What does \n denote?
A newline character
What are strings sequences of?
unicode characters
What type are characters?
char
How are characters formatted?
enclosed by singular quotation marks
e.x.
‘a’
What method returns the char value of a string
charAt
What position is the first character of a string at?
0
What does the substring method do?
extracts a part of a string
What is the syntax of the substring method?
str.substring(start, pastEnd)