CS202 Introduction to
Java
CS202 Introduction to
Java
CS202 Introduction to
Java
CS202 Introduction to
Java
Classes in Java
Class Access Visibility
Members of a Class
Class Access Specifiers
Member Accessibility
Similarities to C++
Similarities to C++
CS202 Introduction to
Java
CS202 Minor Differences
CS202 Introduction to
Java
CS202 Introduction to
Java
Java Identifiers
What is an Identifier?
51 Java Reserved Words
Simplest Java class
Slide 20
What’s in a class
heading?
Syntax for Declarations
Operators?
Operators? Equals()
method
What about Arrays?
Arrays of Objects
Arrays are defined…
Arrays of class type…
Arrays
double[]
salesAmt;
salesAmt = new double[6];
Array Definitions
Another Example
Declaring and Allocating
an Array
Assigning values to array
elements
What values are assigned?
Now what values are
printed?
Initializer List
Passing Arrays as
Arguments
Passing an Array as
Arguments
Memory allocated for
array
Parallel arrays
final int
SIZE = 50 ;
int [ ] idNumber = new
int [ SIZE ] ; // parallel arrays hold
float [ ] hourlyWage = new float [ SIZE ] ; // related information
Partial Array Processing
More about Array Indexes
String[] groceryItems =
new String[10];
String[] groceryItems =
new String[10];
Date[] bigEvents = new
Date[10];
Garbage Collection and
Objects
Garbage Collection and
Objects
Garbage Collectors:
Efficiency?
Clarifying References
Types in Java
Primitive Wrapper Classes
Three Categories of Data
Categories of
Responsibilities
Instance Data
Class Data
Local Data
Functions (ahhh Methods!)
Functions (ahhh Methods!)
Method Declaration Syntax
Methods
Some Definitions
More Definitions
More Definitions
Void Methods
Value-Returning Methods
Value-returning example
The This “Reference”
Constructors
Differences with
Constructors
No Destructors!?
finalize() is not a
destructor!
Inheritance
Accessing Base Class
Members
Is there Hiding? Yes and
No
Constructors in
Hierarchies
If you have a finalize()…
A Java Application
Where do we get started?
main
Main in which class?
Final Methods – a special
case
Final Classes
More Definitions
An example
Another Example
Class Syntax
Overriding vs. Hiding
Polymorphism
Dynamic Binding
Dynamic Binding
Overriding or
Overloading?
Abstract Base Classes
Abstract Base Classes
Interfaces in Java
“Implements” in Java
Multiple Inheritance!
What to use? So many
choices!
Shadowing
Input and Output
Reference Types: A Review
Slide 102
Slide 103
Shallow Copy vs. Deep
Copy
What’s the
difference?
Separate deep copy
Copy Constructor:
Different…
Java String Class
Actions of Java’s String
class
"Why is String
uppercase and..."
Assignment Statement
Syntax
String concatenation (+)
Concatenation Example
Using Java output device
Java Input Devices
Using a Java Input Device
Interactive Input
Interactive Output
continued
Inputting Numeric Values
Predefined Numeric
Classes
Converting Strings to
Numbers
Converting a String to a
Double Value
Java Program
Java program continued
Additional String Methods
String Methods Continued
String Methods Continued
Slide 128
Relational operators
w/Strings?
String methods
"String"
More String Methods
String Method compareTo
Values of each expression
Example of If
statements
(same use of {}, if and else)
A sentinel-controlled
loop
Slide 137
An end-of-file controlled
loop
Slide 139
Flag-controlled loops
A flag-controlled loop
Slide 142
Exception Handling
Exceptions
Three Part Exception
Handling
try-catch with Built-In
Exception
try-catch with Exception
Class
Class DataException
Execution of try-catch
Precedence
Slide 151
"// class List"
Unsorted and Sorted Lists
Methods for Class List
Observer Methods
Observer Methods Contd.
Transformer Method Insert
Before Inserting 64 into
an Unsorted List
After Inserting 64 into
an Unsorted List
Observer Method isThere
Transformer Method Delete
"public void
delete(String item"
"// If item found,"
Iterator Methods
Straight Selection Sort
Selection Sort Algorithm
Selection Sort Code
"public void
insert(String item"
Slide 169
Slide 170
"public boolean
isThere(String item"
Comparable Interface
Slide 173
Slide 174
Slide 175
Initializing Static
Members
Libraries