Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Lesson 3

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.

Note – all java keywords are in lowercase and case-sensitive.

Identifiers – are user-defines names for methods, variables, constants, and classes.

Rules in creating identifiers

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

Data types – defines the type of value a variable must contain.

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.

Variables – are identifiers whose values can be changed.

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.

Example: String Firstname, MiddleName, Lastname;

Constants – are identifiers whose values never change once declared and uses the keyword final

Example final int Score = 10;

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;

Int E = D; //here you see that the value of E is the value of D

Concatenation – the process of joining 2 or more variables. Example int A + B

2 types of casting

Implicit and explicit

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

Answer A and B from pages 33 - 34

You might also like