Java Notes
Expressions
Expressions are the basic way to create values. Expressions are created by combining literals (constants), variables, and method calls by using operators. Parentheses can be used to control the order of evaluation.
Types
Every variable and value has a type. There are two kinds of types:
- Primitive types: byte, short, char, int, long, float, double, boolean.
- Object types: String and array types are builtin, but every class that is defined creates a new object type.
Literals - constants
There is a way to write values of many types (3, 3.0, true, 'a', "abc").
Variables
Every variable must be declared with a type. There are basically three different kinds of variables:
- Local variables in methods.
- Instance variables (often called fields) in objects.
- Class (static) variables in classes.
Operators
Operators are used to combine literals, variables, methods calls, and other expressions. Operators can be put into several conceptual groups.
- Arithmetic operators (+, -, *, /, %, ++, --)
- Comparison Operators (<, <=, ==, >=, >, !=)
- Boolean operators (&&, ||, !, &, !, ^, |, &)
- Bitwise operators (&, |, ^, ~, <<, >>, >>>)
- String concatenation operator (+)
- Other (
instanceof
, ?:) - Assignment operators (=, +=, -=, *=, ...)
Order of evaluation
The order in which expressions are evaluated is basically left to right, with the exception of the assignment operators. It may be changed by the use of parentheses. See the expression summary for the precedence.