SlideShare a Scribd company logo
1 of 21
Advanced Java Programming
CS 537 – Data Structures and Algorithms
The Stack
• The stack is the place where all local variables
are stored
– a local variable is declared in some scope
– Example
int x; // creates the variable x on the stack
• As soon as the scope ends, all local variables
declared in that scope end
– the variable name and its space are gone
– this happens implicitly – the user has no control over
it
The Heap
• The heap is an area of memory that the
user handles explicitly
– user requests memory through new operator
– java does garbage collection to reclaim
unused memory
• A user maintains a handle on memory
allocated in the heap with a reference
variable
Creating Objects
• All objects are created on the heap
• A reference to object is stored on the stack
– simply declaring an object does not create it
• automatically set to null
– new operator allocates space on the heap
Creating Objects
• Example
Object obj1 = new Object();
Object obj2;
main
x = 3
func1
obj1 = 200
obj2 = null
200
Heap
Stack
Object
Assigning Object References
• Reference can be assigned through new
operator
• obj2 = new Object();
• Reference can assigned to another
reference
• obj2 = obj1;
• WARNING
– when assigning to another reference, both
references now refer to the same object
Assigning Object References
• Example
• Object obj1 = new Object();
• Object obj2 = obj1;
main
x = 3
func1
obj1 = 200
obj2 = 200
200
Heap
Stack
Object
Simple Class
class Foo implements Cloneable {
private int num;
public void Foo(int num) { this.num = num; }
public void setNum(int num) { this.num = num; }
public int getNum() { return num; }
}
Copying an Object
• Want to create and modify copy of object
– remember, simple assignment not enough
Foo f1 = new Foo(5);
Foo f2 = f1; // still only one object – 2 references
f2.setNum(10);
System.out.println(“f1’s num = “ + f1.getNum()); // prints 10
System.out.println(“f2’s num = “ + f2.getNum()); // prints 10
– need to use the clone() method
clone() Method
• To use clone() must implement Cloneable
• Object.clone() is automatically inherited by every
class
– by default, it creates a new object and copies all fields
• Example
Foo f1 = new Foo(5);
Foo f2 = f1.clone();
f2.setNum(10);
System.out.println(“f1’s num = “ + f1.getNum()); // prints 5
System.out.println(“f2’s num = “ + f2.getNum()); // prints 10
Shallow Clone
• Only copies the fields
– does not copy what the fields reference
• Doesn’t work well for sophisticated objects
• Example:
Class Foo {
private int [] nums;
public void Foo(int size) { nums = new int[size]; }
…
}
Foo f1 = new Foo(5);
Foo f2 = f1.clone();
Shallow Clone
Foo f1 = new Foo(5);
Foo f2 = f1.clone();
func1
f1 = 200
f2 = 100
200
Heap
Stack
nums = 50
50
Array
nums = 50
100
Deep Clone
• Copies fields and what they refer to
• Must reimplement the clone() method
class Foo {
…
public Object clone() {
try {
Foo fobj = (Foo)super.clone(); // copies fields
fobj.nums = (int)nums.clone(); // arrays implement clone
return fobj;
} catch(CloneNotSupportedException e) { }
}
}
Inheritance
• lets one class inherit fields and methods
from another class
• use keyword extends to explicitly inherit
another classes public and protected
fields/methods
• can only explicitly extend from one class
• all classes implicitly extend the Object
class
Inheritance
• overriding a method
– must have the same signature as original
– declaring a method final means future derived
classes cannot override the method
• overloading a method
– method has same name but different
signature
– they are actually different methods
Inheritance
• abstract classes and methods
– declaring a class abstract
• must have an abstract method
• class cannot be directly used to create an object
• class must be inherited to be used
– declaring a method abstract
• method must be defined in derived class
Abstract Class
abstract class Pixel {
. . .
public abstract void refresh();
}
class ColorPixel extends Pixel {
. . .
public void refresh() {
do some work
}
}
• Note: signature of method in derived class must be
identical to parent declaration of the method
Interface
• basically an abstract class where all
methods are abstract
• cannot use an interface to create an object
• class that uses an interface must
implement all of the interfaces methods
• use the implements keyword
• a class can implement more than one
interface
Interface
• simple example
class Tester implements Foo, Bar {
. . .
}
• Foo and Bar are interfaces
• Tester must define all methods declared in
Foo and Bar
Array Review
• Consecutive blocks of memory
• Creation: int [] grades = new int[25];
• __.length: holds size of array
• __.clone(): makes copy of array data
• out-of-bounds exception: trying to access
data outside of array bounds generates an
exception
• Array size is fixed at creation
Vector Class
• Very similar to an array
• Major difference: vectors can grow beyond
original size
– if a certain capacity is exceeded, a new, larger
memory region is allocated for vector
– copy all data to the new area
• See Java documentation on-line for
complete details

More Related Content

Similar to JavaAdvanced programming for expertes dsd

Similar to JavaAdvanced programming for expertes dsd (20)

Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
00-intro-to-classes.pdf
00-intro-to-classes.pdf00-intro-to-classes.pdf
00-intro-to-classes.pdf
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
Design patterns(red)
Design patterns(red)Design patterns(red)
Design patterns(red)
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Ruby programming introduction
Ruby programming introductionRuby programming introduction
Ruby programming introduction
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year cs
 
inheritance
inheritanceinheritance
inheritance
 
03class
03class03class
03class
 
Pi j2.2 classes
Pi j2.2 classesPi j2.2 classes
Pi j2.2 classes
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 

More from meharikiros2

CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
meharikiros2
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
meharikiros2
 
Emerging chap asasasasasawwqwqwwqwewewr4.pptx
Emerging chap asasasasasawwqwqwwqwewewr4.pptxEmerging chap asasasasasawwqwqwwqwewewr4.pptx
Emerging chap asasasasasawwqwqwwqwewewr4.pptx
meharikiros2
 
chapter1lecturenotes sdsdasdddadad(2).ppt
chapter1lecturenotes sdsdasdddadad(2).pptchapter1lecturenotes sdsdasdddadad(2).ppt
chapter1lecturenotes sdsdasdddadad(2).ppt
meharikiros2
 
Lab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptxLab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptx
meharikiros2
 
Lecture 01 - CS193Jxcxcxcx Summer 2003.ppt
Lecture 01 - CS193Jxcxcxcx Summer 2003.pptLecture 01 - CS193Jxcxcxcx Summer 2003.ppt
Lecture 01 - CS193Jxcxcxcx Summer 2003.ppt
meharikiros2
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cpp
meharikiros2
 
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
SystemsProgrammingCourse FSDFFSFDSDSDSFSFSSystemsProgrammingCourse FSDFFSFDSDSDSFSFS
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
meharikiros2
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 

More from meharikiros2 (13)

CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Emerging chap asasasasasawwqwqwwqwewewr4.pptx
Emerging chap asasasasasawwqwqwwqwewewr4.pptxEmerging chap asasasasasawwqwqwwqwewewr4.pptx
Emerging chap asasasasasawwqwqwwqwewewr4.pptx
 
Chapter-1-IntroDistributeddffsfdfsdf-1.pptx
Chapter-1-IntroDistributeddffsfdfsdf-1.pptxChapter-1-IntroDistributeddffsfdfsdf-1.pptx
Chapter-1-IntroDistributeddffsfdfsdf-1.pptx
 
chapter1lecturenotes sdsdasdddadad(2).ppt
chapter1lecturenotes sdsdasdddadad(2).pptchapter1lecturenotes sdsdasdddadad(2).ppt
chapter1lecturenotes sdsdasdddadad(2).ppt
 
Lab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptxLab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptx
 
RIFLI-Computer-Basics-Part-1-1 lecture not
RIFLI-Computer-Basics-Part-1-1  lecture notRIFLI-Computer-Basics-Part-1-1  lecture not
RIFLI-Computer-Basics-Part-1-1 lecture not
 
Lecture 01 - CS193Jxcxcxcx Summer 2003.ppt
Lecture 01 - CS193Jxcxcxcx Summer 2003.pptLecture 01 - CS193Jxcxcxcx Summer 2003.ppt
Lecture 01 - CS193Jxcxcxcx Summer 2003.ppt
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cpp
 
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
SystemsProgrammingCourse FSDFFSFDSDSDSFSFSSystemsProgrammingCourse FSDFFSFDSDSDSFSFS
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
This is introduction to distributed systems for the revised curiculum
This is introduction to distributed systems for the revised curiculumThis is introduction to distributed systems for the revised curiculum
This is introduction to distributed systems for the revised curiculum
 
ITET-4.pptx
ITET-4.pptxITET-4.pptx
ITET-4.pptx
 

Recently uploaded

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

JavaAdvanced programming for expertes dsd

  • 1. Advanced Java Programming CS 537 – Data Structures and Algorithms
  • 2. The Stack • The stack is the place where all local variables are stored – a local variable is declared in some scope – Example int x; // creates the variable x on the stack • As soon as the scope ends, all local variables declared in that scope end – the variable name and its space are gone – this happens implicitly – the user has no control over it
  • 3. The Heap • The heap is an area of memory that the user handles explicitly – user requests memory through new operator – java does garbage collection to reclaim unused memory • A user maintains a handle on memory allocated in the heap with a reference variable
  • 4. Creating Objects • All objects are created on the heap • A reference to object is stored on the stack – simply declaring an object does not create it • automatically set to null – new operator allocates space on the heap
  • 5. Creating Objects • Example Object obj1 = new Object(); Object obj2; main x = 3 func1 obj1 = 200 obj2 = null 200 Heap Stack Object
  • 6. Assigning Object References • Reference can be assigned through new operator • obj2 = new Object(); • Reference can assigned to another reference • obj2 = obj1; • WARNING – when assigning to another reference, both references now refer to the same object
  • 7. Assigning Object References • Example • Object obj1 = new Object(); • Object obj2 = obj1; main x = 3 func1 obj1 = 200 obj2 = 200 200 Heap Stack Object
  • 8. Simple Class class Foo implements Cloneable { private int num; public void Foo(int num) { this.num = num; } public void setNum(int num) { this.num = num; } public int getNum() { return num; } }
  • 9. Copying an Object • Want to create and modify copy of object – remember, simple assignment not enough Foo f1 = new Foo(5); Foo f2 = f1; // still only one object – 2 references f2.setNum(10); System.out.println(“f1’s num = “ + f1.getNum()); // prints 10 System.out.println(“f2’s num = “ + f2.getNum()); // prints 10 – need to use the clone() method
  • 10. clone() Method • To use clone() must implement Cloneable • Object.clone() is automatically inherited by every class – by default, it creates a new object and copies all fields • Example Foo f1 = new Foo(5); Foo f2 = f1.clone(); f2.setNum(10); System.out.println(“f1’s num = “ + f1.getNum()); // prints 5 System.out.println(“f2’s num = “ + f2.getNum()); // prints 10
  • 11. Shallow Clone • Only copies the fields – does not copy what the fields reference • Doesn’t work well for sophisticated objects • Example: Class Foo { private int [] nums; public void Foo(int size) { nums = new int[size]; } … } Foo f1 = new Foo(5); Foo f2 = f1.clone();
  • 12. Shallow Clone Foo f1 = new Foo(5); Foo f2 = f1.clone(); func1 f1 = 200 f2 = 100 200 Heap Stack nums = 50 50 Array nums = 50 100
  • 13. Deep Clone • Copies fields and what they refer to • Must reimplement the clone() method class Foo { … public Object clone() { try { Foo fobj = (Foo)super.clone(); // copies fields fobj.nums = (int)nums.clone(); // arrays implement clone return fobj; } catch(CloneNotSupportedException e) { } } }
  • 14. Inheritance • lets one class inherit fields and methods from another class • use keyword extends to explicitly inherit another classes public and protected fields/methods • can only explicitly extend from one class • all classes implicitly extend the Object class
  • 15. Inheritance • overriding a method – must have the same signature as original – declaring a method final means future derived classes cannot override the method • overloading a method – method has same name but different signature – they are actually different methods
  • 16. Inheritance • abstract classes and methods – declaring a class abstract • must have an abstract method • class cannot be directly used to create an object • class must be inherited to be used – declaring a method abstract • method must be defined in derived class
  • 17. Abstract Class abstract class Pixel { . . . public abstract void refresh(); } class ColorPixel extends Pixel { . . . public void refresh() { do some work } } • Note: signature of method in derived class must be identical to parent declaration of the method
  • 18. Interface • basically an abstract class where all methods are abstract • cannot use an interface to create an object • class that uses an interface must implement all of the interfaces methods • use the implements keyword • a class can implement more than one interface
  • 19. Interface • simple example class Tester implements Foo, Bar { . . . } • Foo and Bar are interfaces • Tester must define all methods declared in Foo and Bar
  • 20. Array Review • Consecutive blocks of memory • Creation: int [] grades = new int[25]; • __.length: holds size of array • __.clone(): makes copy of array data • out-of-bounds exception: trying to access data outside of array bounds generates an exception • Array size is fixed at creation
  • 21. Vector Class • Very similar to an array • Major difference: vectors can grow beyond original size – if a certain capacity is exceeded, a new, larger memory region is allocated for vector – copy all data to the new area • See Java documentation on-line for complete details