procedural programming with Java Flashcards
Objects within a class:(2)
-have the same methods
-can have different data associated with them
syntax
describes allowed arrangements of words and
punctuation in a program (how you write a program)
semantics
describes what happens when you run the
program
There are three commonly recognized types of errors:
syntax error– grammatical mistake in the program
run-time error– error that is not detected until program is run
logic error– mistake in the underlying algorithm for the
program(the outcome is wrong)
Variable
a data container that stores the data values during
program execution.
identifier, rules for constructing identifiers:
The name of a variable or other item in a program,
must not start with a digit
all the characters must be letters, digits, the symbols _ or $
The size range of the integer type
−2^(31) to 2^(31) − 1
Memory used for boolean
1 byte
Memory used for char
2 bytes
Memory used for short
2 bytes
Memory used for int
4 bytes
Memory used for long
8 bytes
Memory used for float
4 bytes
Memory used for double
8 byte
scientific notation or floating-point notation
The literals with an e or E (for exponent) 3.67e5
You can assign a value of any type in the following list to a variable of any type that appears further down in the list:
byte -> short -> int -> long -> float -> double
Operators are classified based on how many operands they take.
The classes are:
unary (one operand),
e.g.-12, a++, !flag
binary (two operands),
e.g. a * b, c»_space; 1, f || g
ternary (three operands),
e.g. flag ? “YES” : “NO”
Java allows to form expressions using variables, constants, and the arithmetic operators:
+ (addition), − (subtraction), ∗ (multiplication),
/ (division), % (modulo, remainder)
Java Precedence Rules
expr++, -expr∼ !, * / %, + -, shift, < > <= >= instanceof, == !=, &, ^, |, &&, ||, ? :, = +=
associativity rules
Unary operators have right to left associativity,
Binary operators have left to right associativity,
Assignment operators (unlike the other binary operators) have
right to left associativity,
The ternary operator has right to left associativity
postfix
increment and decrement expressions evaluate to the
existing value of the variable and only afterwards update it
prefix
increment and decrement expressions first update the value of the variable and then evaluate to this value
raional operators
==, >, <
logical operators
! NOT, negation
|| Logical OR, disjunction
&& Logical AND, conjunction