COP2253 Zybooks Chapter Two Flashcards
variable
a named item used to hold a value
assignment
assigns a variable with a value
an assignments left side must be a
variable
= symbol is
an assignment of a left-side variable with a right-side value (NOT equality as in mathematics)
incrementing
increasing a variables value by 1
variable declaration
a statement that declares a variable, specifying the variable’s name and type
assignment statement
a statement that assigns the variable on the left-side of the = with the current value of the right-side expression
expression
a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value
an integer appearing in an expression is known as an
integer literal
identifier
a case-sensitive name created by a programmer for an item like a variable or method
reserved word (or keyword)
a word that is part of the language that cannot be used as an identifier
camel case
abuts multiple words, capitalizing each word except the first
literal
a specific value in code
operator
a symbol that performs a built-in calculation (like +-*/)
when an expression evaluates to a value it
replaces the expression
precedence rules
in order:
unary -
*/%
+-
left-to-right
~~~
```
unary minus -
minus used as a negative
compound variables
shorthand way to update a variable (ex. +=)
Should you include commas in an integer literal?
NO
floating-point number
a real number containing a decimal point that can appear anywhere (or “float”) in the number
double variable
stores a floating-point number
floating-point literal
a number with a fractional part, even if the fraction is 0 as in 1.0
What statement reads a floating-point value from input?
scnr.nextDouble();
Integer variables are typically used for values that are___?
counted
floating-point variables are typically used for values that are ___?
measured
Dividing a non-zero floating-point number by zero results in:
infinity or -infinity
NaN indicates:
(not a number) an unrepresentable or undefined value
scientific notation
written as e preceding the power-of-10 exponent, as in 6.02e33
constant variable (or final variable)
an initialized variable whose value cannot be changed, usually named in uppercase and separated by underscores. variable declaration is preceded with keyword final
method
a list of statements executed by invoking the method’s name (via method call)
arguments
method input values, appear within (), separated by commas
modulo operator
%, evaluates the remainder of the division of two integer operands
type conversion
a conversion of one data type to another
implicit conversion
automatic type conversion
type cast (type)
explicitly converts a value of one type to another type (ex. (double)myIntVar)
variable char type
stores a single character
character literal
character surrounded with single quotes, as in ‘k’
What statement reads a character from input?
scnr.next().charAt(0);
string
sequence of characters
string literal
surrounds a character sequence with double quotes
object
consists of some internal data items plus operations that can be performed on that data
scnr.next()
reads a string from input until reaching a whitespace
What statement reads all of the text on the current input line?
scnr.nextLine()
overflow
occurs when the value being assigned to a variable is greater than the maximum value the variable can store
numeric data type long
used for integers expected to exceed about 2 billion
Random class
provides methods that return a random integer
What statement imports the Random class?
import java.util.Random;
API
application programming interface
module
a group of related packages
package
a group of related classes
debugging (or troubleshooting)
the process of determining and fixing the cause of a problem in a program
output formatting
adjusting the way that a program’s output appears
format specifiers
specifies the type of value to print in it’s place, begins with the % character followed by another character that indicates the value type to be printed