Lesson 3: Built-In Data Types – Part 2


Definitions

Identifiers: Identifiers are used to name variables. It is a sequence of letters, digits and other characters (_, -, $), but cannot start with a digit. Identifiers are case sensitive

Literals: A literal is a source-code representation of a data-type value. For example, 1234 or 99 are literal values of the data type int. 3.14159 is a floating point literal of a double data type.

Variables: A variable is a name that we use to refer to a data type value. Variables are used to keep track of changing values. Variables are created by declaring its data type and giving it a name. Camel Case variable naming convention.

Declaration Statements: A declaration statement associates a variable name with a data type at compile time. Variables must be declared and given a name before they can be used in a program.

Assignment Statements: An assignment statement associates a data type value with a variable. For example, c = a + b is an action rather than an expression of equality. It really means set the value of variable c to be the value of a plus b.

Initialization: In a declaration statement, the initial value of the variable is undefined We can assign an initial value to the variable in our declaration statement.

Expressions: An expression is a literal, a variable or a sequence of operations on literals and/or variables that produce a value.

Precedence: Expressions specify a sequence of computations and follow basic rules. In arithmetic operations, multiplication and division are performed first, then addition and subtraction. Order of operations is the same in programming as it is in Mathematics, left-associativity. Parentheses are used to override the rules.

Converting Strings to primitive values: Java provides a set of library methods that can be used to convert Strings into numeric values for primitive types.

Integer.parseInt()
Double.parseDouble()
Arithmetic Operator Description
= Assignment
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division (returns the remainder of a division)
++ Increment by 1
-- Decrement by -1
+=
-=
*=
/=
Compound addition
Compound subtraction
Compound multiplication
Compound division