CC102 Lesson 3 Bsit - PPT Variables Data Types
CC102 Lesson 3 Bsit - PPT Variables Data Types
ding Data
Types
LEARNING OUTCOMES:
At the end of the session, the students should be able to:
1. Define appropriate data type for different
programming scenario
2. Can identify the different keyword categorically
3. Develop code that declares, initializes, and uses
primitives, arrays, enums, and objects as static,
instance, and local variables.
3. Write code that determines the equality of two
objects or two primitives.
boolean b =
boolean false, true
true;
Other
void -- --
Syntax in declaring
Variable
• The general syntax for declaring and initializing
a variable:
<modifier> <dataType>
<variableName> (assignment Op)
<initial/literal Value>;
Accessing Variables
• Once you declare a variable, you can access it
by referring to it by its name:
x = y;
Literals
• A literal is a value assigned to a variable in the
source code
int id = 10;
The boolean Literals: true or false
The char Literals: ‘L’, ‘\u4567’, ‘\n’
The Integral Literals: 43, 43L, 053, 0x2b
The Floating-Point Literals: 12.33, 1.25E+8, 1.2534f
Sample
program
Using Assignment
Operator
• used to set
(or reset)
the value of
a variable:
x = 7;
• shortcut
assignment
operators:
Naming Variables
1. Each variable has a name, called an identifier.
2. Rules to name a variable:
• The first character must be a letter, a dollar sign ($),
or an underscore (_).
• A character other than the first character in an
identifier may be a letter, a dollar sign, an underscore,
or a digit.
• None of the Java language keywords (or reserved
words) can be used as identifiers.
3. Maximum character length for an identifier: Unlimited
Java SE 10 Edition
JAVA Keywords