Begins with a backslash followed by a character
Represents a single nonprinting character
char aNewLine = ' ';
Back
showInputDialog() method
Front
Six overloaded versions
Returns a String representing a user's response
Back
Reasons for using named constants:
Front
Make programs easier to read and understand
Enable you to change a value at one location within a program
Reduce typographical errors
Stand out as separate from variables
Back
Variable
Front
A named memory location
Used to store a value
Can hold only one value at a time
Its value can change
Back
boolean variable
Front
Can hold only one of two values
true or false
boolean isItPayday = false;
Back
Front
Back
Dialog boxes used to accept user input
Front
Input dialog box
Confirm dialog box
Back
Keyboard buffer
Front
Location in memory that stores all keystrokes, including Enter
To avoid issues, add an extra nextLine()method call to retrieve the abandoned Enter key character after numeric or next() inputs
Back
Reference types
Front
More complex data types
Back
Data type
Front
A type of data that can be stored
How much memory an item occupies
What types of operations can be performed on data
Back
Concatenated
Front
A numeric variable is concatenated to a String using the plus sign
The entire expression becomes a String
The println() method can accept a number or String
Back
Assignment operator
Front
The equal sign (=)
The value to the right is assigned to the variable on the left
Back
Literal constant
Front
Value taken literally at each use
Back
Scanner object
Front
Breaks input into units called tokens
Back
Declaring and Using Constants and Variables
Front
Back
System.in object
Front
Standard input device
Normally the keyboard
Access using the Scanner class
Back
There is a problem when using one numeric
Front
Scanner class retrieval method or next()method before using the nextLine()method
Back
String
Front
A built-in class
Stores and manipulates character strings
String constants are written between double quotation marks
Back
Variable declaration
Front
A statement that reserves a named memory location
Includes:
Data type
Identifier
Optional assignment operator and assigned value
Ending semicolon
Back
Variations of the integer type
Front
byte
short
long
Back
Primitive type
Front
A simple data type
Back
A named constant:
Front
Should not change during program execution
Has a data type, name, and value
Has a data type preceded by the keyword final
Can be assigned a value only once
Conventionally is given identifiers using all uppercase letters
Back
Numeric constant
Front
As opposed to a literal constant
Back
Prompt
Front
A message requesting user input
Back
Declaring Variables
Front
Declare multiple variables of the same type in separate statements on different lines
int myAge = 25;
int yourAge = 19;
When declaring variables of different types, you must use a separate statement for each type
Back
Assignment
Front
An assignment made after a variable is declared
Back
Operand
Front
A value used on either side of an operator
Back
Front
Back
Standard arithmetic operators
Front
Perform calculations with values in programs
Back
char data type
Front
Holds any single character
Back
后面size in bytes背下来!!
Front
Back
Name variables
Front
Use naming rules for legal class identifiers
Back
Floating-point data types
Front
float
double
Back
int data type
Front
Stores an integer, or whole number
Value from -2,147,483,648 to +2,147,483,647
Back
Initialization
Front
An assignment made when declaring a variable
Back
Unnamed constant
Front
No identifier is associated with it
Back
Scope
Front
The area in which a data item is visible to a program, and in which you can refer to it using its simple identifier.
A variable or constant is in scope from the point it is declared.
Until the end of the block of code where the declaration lies
Back
Input dialog box
Front
Asks a question
Provides a text field in which the user can enter a response
Back
Boolean logic
Front
Based on true-or-false comparisons
Back
Associativity
Front
The order in which operands are used with operators
Back
Floating-point number
Front
Contains decimal positions
Back
print() or println() statement
Front
Use alone or in combination with a String
Back
Place constant character values within single quotation marks
Front
char myMiddleInitial = 'M';
Back
Relational operator (comparison operator)
Front
Compares two items
Back
Front
Back
Significant digits
Front
Refers to mathematical accuracy
Back
To produce console output on multiple lines in the command window, use one of these options:
Front
Use the newline escape sequence
Use the println() method multiple times
Back
Front
Back
Constant
Front
Cannot be changed while program is running
Back
Front
Back
Section 2
(16 cards)
Arithmetic with variables or constants of the same type
Arithmetic operations with operands of unlike types
Front
Java chooses the unifying type for the result
Back
Avoid unnecessary repetition of arithmetic statements
Front
Back
Cast operator
Front
Place desired result type in parentheses
Using a cast operator is an explicit conversion
You do not need to perform a cast when assigning a value to a higher unifying type
Back
Declaring and Using a Variable
Working with Integers
Working with the char Data Type
Accepting User Input
Using Arithmetic Operators
Implicit and Explicit Casting
Front
Don't attempt to assign a literal constant floating-point number
Don't forget precedence rules
Don't forget that integer division results in an integer
Don't attempt to assign a constant decimal value to an integer using a leading 0
Don't use a single equal sign (=) in a Boolean comparison for equality
Don't try to store a string of characters in a char variable.
Don't forget that when a String and a numeric value are concatenated, the resulting expression is a string
Don't forget to consume the Enter key after numeric input using the Scanner class when a nextLine()method call follows
Don't forget to use the appropriate import statement when using the Scanner or JOptionPane class
Back
Variables
Named memory locations
Primitive data types
Standard arithmetic operators for integers:
+, _, *, /, and %
Boolean type
true or false value
Relational operators:
>, <, ==, >=, <=, and !=
Front
Floating-point data types
float
double
char data type
Scanner class
Access keyboard input
JOptionPane
Confirm dialog box
Input dialog box
Back
Automatic Type Conversion
Front
Automatically converts nonconforming operands to the unifying type
Order for establishing unifying types between two variables (highest to lowest):
double
float
long
int
Back
Operator precedence
Front
The rules for the order in which parts of mathematical expressions are evaluated
First multiplication, division, and remainder (modulus), then addition or subtraction
Back
Front
Back
Integer values are exact
Front
But floating-point numbers frequently are only approximations
Back
Type casting
Front
Forces a value of one data type to be used as a value of another data type