Should begin with a letter and may contain additional letters and digits. Identifiers are the same
as variables.
Use descriptive n Use single letters only for the counter in loops.
Variable names start with lower-case
Multi-word identifiers are internally capitalized
Do not use hyphens or underscores to separate multi-word identifiers.
Need to print extra characters?
What about the unicode set?
This is the format: \\uHHHH
Remember any other escape characters such as \ , \\t and \\\\?
The following lists some of these conventions based on the type of identifier:
Class name
The first letter of each word is capitalized, examples:
Mammal, SeaMammal
Function name
The first letter of each, except the first, word is capitalized, examples:
getAge, setHeight
Variable name
The first letter of each, except the first, word is capitalized, examples:
age, brainSize
Constant names
Every letter is capitalized and underscores are used between words, examples:
MAX_HEIGHT, MAX_AGE
RESERVED WORDS
As you may have noticed, many of Java\'s keywords are borrowed from C/C++. Also, as in
C/C++, keywords are always written in lowercase.
Data declaration keywords (boolean, float, int)
Loop keywords (continue, while, for)
Conditional keywords (if, else, switch)
Exception keywords (try, throw, catch)
Structure keywords (class, extends)
Modifier and access keywords (private, public)
Miscellaneous keywords (true, null)
The following keywords and their use, you SHOULD know.
boolean default for private switch
break double if protected this
case else import public throws
catch extends int return try
char final new static void
class float package super while
VARIABLE SCOPE
Where is it appropriate to declare a variable? Does it make a difference?
PRIMITIVE DATA TYPES
int (16-bit)
float (32-bit)
double (64-bit
boolean (true/false)
char (16-bit unicode)
What about String?
What about Integer, and Double?
OBJECTS
Why object oriented programming?
Objects need to be built, so we need constructors.
Instance variables and the role they play when defining objects.
What about methods of an object?
ARRAYS
int[] array = new int[5]; // one-dimensional array
it may also be declared as:
int[] array = {1, 2, 3, 4, 5}; // it is initialized and declared at the same time.
Arrays can be of any primitive data type or object. Arrays have an instance variable \"length\"
that we can access to find out how big the array is. Remember that an Array can throw an
IndexOutOfBoundsException. Make use of it to make your code safe.
VECTORS
Must import java.util.*;
Unlike arrays, vectors can only hold objects, no primitive data types are allowed. Vectors can
grow big and unbounded. You may want to specify the capacity of the vector but you dont need
to. The default capacity is 10 and it doubles in size every time the capacity is reached.
Just like arrays have the \"length\" instance variable, Vectors have a .size() method that returns
the current size of the vector.
void .addElement(Object obj)
void .setElementA.
Should begin with a letter and may contain additional letters and di.pdf
1. Should begin with a letter and may contain additional letters and digits. Identifiers are the same
as variables.
Use descriptive n Use single letters only for the counter in loops.
Variable names start with lower-case
Multi-word identifiers are internally capitalized
Do not use hyphens or underscores to separate multi-word identifiers.
Need to print extra characters?
What about the unicode set?
This is the format: uHHHH
Remember any other escape characters such as , t and ?
The following lists some of these conventions based on the type of identifier:
Class name
The first letter of each word is capitalized, examples:
Mammal, SeaMammal
Function name
The first letter of each, except the first, word is capitalized, examples:
getAge, setHeight
Variable name
The first letter of each, except the first, word is capitalized, examples:
age, brainSize
Constant names
Every letter is capitalized and underscores are used between words, examples:
MAX_HEIGHT, MAX_AGE
RESERVED WORDS
As you may have noticed, many of Java's keywords are borrowed from C/C++. Also, as in
C/C++, keywords are always written in lowercase.
Data declaration keywords (boolean, float, int)
Loop keywords (continue, while, for)
Conditional keywords (if, else, switch)
Exception keywords (try, throw, catch)
Structure keywords (class, extends)
Modifier and access keywords (private, public)
Miscellaneous keywords (true, null)
The following keywords and their use, you SHOULD know.
boolean default for private switch
2. break double if protected this
case else import public throws
catch extends int return try
char final new static void
class float package super while
VARIABLE SCOPE
Where is it appropriate to declare a variable? Does it make a difference?
PRIMITIVE DATA TYPES
int (16-bit)
float (32-bit)
double (64-bit
boolean (true/false)
char (16-bit unicode)
What about String?
What about Integer, and Double?
OBJECTS
Why object oriented programming?
Objects need to be built, so we need constructors.
Instance variables and the role they play when defining objects.
What about methods of an object?
ARRAYS
int[] array = new int[5]; // one-dimensional array
it may also be declared as:
int[] array = {1, 2, 3, 4, 5}; // it is initialized and declared at the same time.
Arrays can be of any primitive data type or object. Arrays have an instance variable "length"
that we can access to find out how big the array is. Remember that an Array can throw an
IndexOutOfBoundsException. Make use of it to make your code safe.
VECTORS
Must import java.util.*;
Unlike arrays, vectors can only hold objects, no primitive data types are allowed. Vectors can
grow big and unbounded. You may want to specify the capacity of the vector but you dont need
to. The default capacity is 10 and it doubles in size every time the capacity is reached.
Just like arrays have the "length" instance variable, Vectors have a .size() method that returns
the current size of the vector.
3. void .addElement(Object obj)
void .setElementAt(Object obj, int index)
Object .elementAt(int index)
void .insertElementAt(Object obj, int index)
void .removeElementAt(Object obj, int index)
ENUMERATION
This is an iterator and it is very important concept in data structures for ICS211. An Enumeration
lets us visit every element of a Vector one by one.
Vector v = new Vector();
Enumeration e = v.elements();
While(e.hasMoreElements()){
Object o = e.nextElement;
// we do something with each element.
}
OPERATORS AND PRECEDENCE IN JAVA
Pages 436, 437 AND 438
You need to know:
Arithmetic operators in table A7.
Incrementing and decrementing operators int Table A.8.
Good to know but not necessary the Assignment operators in table A.9
Relational operators in table A.10
Logical operators in table A.11
FLOW CONTROL / REPETITION STATEMENTS
Must be familiar with:
for loops
while loops
if statements
switch case statements
The student must be familiar with:
Creating customized classes and methods.
JAVA Applets
JAVA Stand-alone applications
Compiling and running JAVA programs
Solution
4. Should begin with a letter and may contain additional letters and digits. Identifiers are the same
as variables.
Use descriptive n Use single letters only for the counter in loops.
Variable names start with lower-case
Multi-word identifiers are internally capitalized
Do not use hyphens or underscores to separate multi-word identifiers.
Need to print extra characters?
What about the unicode set?
This is the format: uHHHH
Remember any other escape characters such as , t and ?
The following lists some of these conventions based on the type of identifier:
Class name
The first letter of each word is capitalized, examples:
Mammal, SeaMammal
Function name
The first letter of each, except the first, word is capitalized, examples:
getAge, setHeight
Variable name
The first letter of each, except the first, word is capitalized, examples:
age, brainSize
Constant names
Every letter is capitalized and underscores are used between words, examples:
MAX_HEIGHT, MAX_AGE
RESERVED WORDS
As you may have noticed, many of Java's keywords are borrowed from C/C++. Also, as in
C/C++, keywords are always written in lowercase.
Data declaration keywords (boolean, float, int)
Loop keywords (continue, while, for)
Conditional keywords (if, else, switch)
Exception keywords (try, throw, catch)
Structure keywords (class, extends)
Modifier and access keywords (private, public)
Miscellaneous keywords (true, null)
The following keywords and their use, you SHOULD know.
boolean default for private switch
5. break double if protected this
case else import public throws
catch extends int return try
char final new static void
class float package super while
VARIABLE SCOPE
Where is it appropriate to declare a variable? Does it make a difference?
PRIMITIVE DATA TYPES
int (16-bit)
float (32-bit)
double (64-bit
boolean (true/false)
char (16-bit unicode)
What about String?
What about Integer, and Double?
OBJECTS
Why object oriented programming?
Objects need to be built, so we need constructors.
Instance variables and the role they play when defining objects.
What about methods of an object?
ARRAYS
int[] array = new int[5]; // one-dimensional array
it may also be declared as:
int[] array = {1, 2, 3, 4, 5}; // it is initialized and declared at the same time.
Arrays can be of any primitive data type or object. Arrays have an instance variable "length"
that we can access to find out how big the array is. Remember that an Array can throw an
IndexOutOfBoundsException. Make use of it to make your code safe.
VECTORS
Must import java.util.*;
Unlike arrays, vectors can only hold objects, no primitive data types are allowed. Vectors can
grow big and unbounded. You may want to specify the capacity of the vector but you dont need
to. The default capacity is 10 and it doubles in size every time the capacity is reached.
Just like arrays have the "length" instance variable, Vectors have a .size() method that returns
the current size of the vector.
6. void .addElement(Object obj)
void .setElementAt(Object obj, int index)
Object .elementAt(int index)
void .insertElementAt(Object obj, int index)
void .removeElementAt(Object obj, int index)
ENUMERATION
This is an iterator and it is very important concept in data structures for ICS211. An Enumeration
lets us visit every element of a Vector one by one.
Vector v = new Vector();
Enumeration e = v.elements();
While(e.hasMoreElements()){
Object o = e.nextElement;
// we do something with each element.
}
OPERATORS AND PRECEDENCE IN JAVA
Pages 436, 437 AND 438
You need to know:
Arithmetic operators in table A7.
Incrementing and decrementing operators int Table A.8.
Good to know but not necessary the Assignment operators in table A.9
Relational operators in table A.10
Logical operators in table A.11
FLOW CONTROL / REPETITION STATEMENTS
Must be familiar with:
for loops
while loops
if statements
switch case statements
The student must be familiar with:
Creating customized classes and methods.
JAVA Applets
JAVA Stand-alone applications
Compiling and running JAVA programs