Professional Documents
Culture Documents
Understanding Java
Understanding Java
Java Keywords – terms in Java that are reserved for specific uses. The Java compiler recognizes these
keywords for specific purposes that is why we are not allowed to use them as identifiers.
Identifiers – are user-defines names for methods, variables, constants, and classes.
1. First character of identifier should start with a letter, an underscore ( _ ), or a dollar sign.
After that it can be followed by alphanumeric
2. Create identifier that are descriptive. Good practice to capitalize the first letter.
3. No spaces.
Examples: Class_Main, Arithmetic_Operators, $FirstName, $Last_Name
A. String – alphanumeric
B. Boolean – a logical data type values are True (1), False (0)
C. Char – one character, a number or letter example ‘A’ ‘1’ (only 1 quote is used in char)
D. Byte – 1
E. short – 11
F. int – 167
G. long – 11167L
H. float – 63.5F
I. double 63.5
Literals – are values assigned to variables or constants. Example String = ABCDEFG123 the underlined
word is the literal.
Syntax – the pattern on how codes are written. Example <data_type> <identifier> = int Salary
<data type> <identifier> = <literals> the example is ------- int Salary = 1000;
Each line of defining variables are terminated or ended with a semi colon.
You can declare many variable in the same kind of data type.
Constants – are identifiers whose values never change once declared and uses the keyword final
Casting – is the process of assigning a value or variable of a specific type to a variable of another type.
Example int A = 1, B = 2, C = 3;
Int D = A + B;
2 types of casting
Explicit casting – casting from a value that occupies less memory to another type that occupies more
memory. Example int data type doesn’t have decimals place, if you need to show decimal places you will
use Average.
Implicit casting – casting from a value that occupies large memory to another type that occupies less
memory
Seat work