ITE106 – Data Structures &
Algorithm
Java Programming
Identifiers
• User-defined names for methods, variables,
constants and classes.
Valid Identifiers Invalid Identifiers
MyIdentifierName My Identifier Name
myidentifiername my+identifier+name
my_identifier_name my-identifier-name
_myidentifiername my_identifier’s_name
$myidentifiername my_identifier_&_name
_3names 3names
• An identifier cannot have spaces
• Identifiers cannot begin with a digit/number.
Data Types
Data Type Example/s
String “hello world”
boolean true, false
int ‘A’, ‘z’, ‘\n’, ‘6’
float 63.5
double 73.7
• boolean is a logical data type. In java, it has two possible
values: true or false
Variables
• Variables are identifiers whose values can be
changed. They hold information in our program.
<data_type> <identifier>;
• if you wish to declare a variable with an initial value, the
syntax is:
<data_type> <identifier> =<literal>;
Constants
• Constants are identifiers whose values never
change once declared.
final <type> <identifier> = <literal> ;
• EXAMPLE
final string Student_Bday = “11 – 12 – 1991”
final char gender = “m”;
final double Student_Allowance = 999.99;
Casting
• Casting is the process of assigning a value or
variable of a specific type to a variable of another
type.
Scanner
• Class that handles input from a user. - new is used to
create new
objects from a
class
- create an object
from the
Scanner class
- call a method
- next gets the
next string of text
that a user types
on the keyboard.