Professional Documents
Culture Documents
Identifiers, Keywords and Types
Identifiers, Keywords and Types
Objectives
/* Comment on one or
more lines */
char
Represents a 16 bit Unicode character
Must have its literal enclosed in single quotes(‘ ‘)
Uses the following notations
‘a’ The letter a
‘\t’ A tab
‘\u????’ A specific unicode character
Eg. ‘\u03A6’ is the Greek letter phi ϕ
Textual – char and String
String
Is not a primitive data type, it is a class
Has its literal enclosed in double quotes (“ ”)
“The quick brown fox jumps over the lazy dog”
Example
String greeting=“Good Morning!!\n”;
String errorMessage=“Record not found!”;
Integral- byte, short, int and long
Default is double
Floating point literal includes either a decimal point or
one of the following:
E or e (exponential value)
F or f (float)
D or d (double)
Note –
Floating point literals are double unless
explicitly declared as float
Java Reference Types
day 0
month 0
year 0
Explicit Attribute Initialization
dob ????
day 1
month 1
year 2002
dob ????
day 17
month 3
year 1976
dob 0x91abcdef
day 17
month 3
year 1976
int x = 7;
int y = x;
MyDate s = new MyDate(22, 7, 1974);
MyDate t = s;
t = new MyDate(22, 12, 1974);
Pass-by-Value
The Java programming language only passes
arguments by value
When an object instance is passed as an
argument to a method, the value of the
argument is a reference to the object
The contents of the object can be changed in
the called method, but the object reference is
never changed
PassTest.java
The this Reference
Packages
package banking.objects;
Classes
class SavingAccount;
Interfaces
interface Account
Methods
balance Account()
Variables Constants
currentCustomer() HEAD_COUNT
MAXIMUM_SIZE
Expressions and Flow Control
Objectives
The + operator
Performs String Concatenation
Produces a new String:
String salutation = “Dr.”;
String name = “James” + “ “ + “Gosling”;
String title=salutation+” “+name;
One argument must be a String object
Non-strings are converted to String objects automatically
Casting