SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Chapter 5:  Enhancing Classes  Presentation slides for Java Software Solutions for AP* Computer Science by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by Addison-Wesley Presentation slides are copyright 2002 by John Lewis, William Loftus, and Cara Cocking. All rights reserved. Instructors using the textbook may use and modify these slides for pedagogical purposes. *AP is a registered trademark of The College Entrance Examination Board which was not involved in the production of, and does not endorse, this product.
Enhancing Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
References ,[object Object],[object Object],[object Object],bishop1
The null Reference ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The null Reference ,[object Object],[object Object],[object Object],[object Object]
The this Reference ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assignment Revisited ,[object Object],[object Object],[object Object],Before num1 5 num2 12 After num1 5 num2 5
Reference Assignment ,[object Object],[object Object],Before bishop1 bishop2 After bishop1 bishop2
Aliases ,[object Object],[object Object],[object Object],[object Object]
Testing Objects for Equality ,[object Object],[object Object],[object Object],[object Object],[object Object]
Objects as Parameters ,[object Object],[object Object],[object Object],[object Object]
Passing Objects to Methods ,[object Object],[object Object],[object Object],[object Object],[object Object]
The static Modifier ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static Variables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static Methods Because it is static, the method can be invoked as: value = Helper.triple (5); public static int triple (int num) { int result; result = num * 3; return result; } class Helper
Static Methods ,[object Object],[object Object],[object Object],[object Object]
The static Modifier ,[object Object],[object Object],[object Object]
Exceptions ,[object Object],[object Object],[object Object],[object Object]
Exception Handling ,[object Object],[object Object],[object Object],[object Object],[object Object]
Exception Handling ,[object Object],[object Object],[object Object],[object Object]
The throw Statement ,[object Object],[object Object],[object Object],throw new NoSuchElementException();
Interfaces ,[object Object],[object Object],[object Object],[object Object]
Interfaces public interface Doable { public void doThis(); public int doThat(); public void doThis2 (double value, char ch); public boolean doTheOther (int num); } None of the methods in an interface are given a definition (body) interface is a reserved word A semicolon immediately follows each method header
Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interfaces public class CanDo implements Doable { public void doThis () { // whatever } public void doThat () { // whatever } // etc. } implements is a reserved word Each method listed in Doable is given a definition
Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interfaces ,[object Object],[object Object],[object Object],class ManyThings implements interface1, interface2 { // all methods of both interfaces }
Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object]
The Comparable Interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The List Interface ,[object Object],[object Object],[object Object],[object Object]
Iterator and ListIterator Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object]
Designing Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nested Classes ,[object Object],[object Object],Enclosing Class Nested Class
Nested Classes ,[object Object],[object Object],[object Object],[object Object]
Nested Classes ,[object Object],[object Object],[object Object],[object Object],[object Object]
Inner Classes ,[object Object],[object Object],[object Object]
Dialog Boxes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The EvenOdd Program
Graphical User Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Events ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Events and Listeners ,[object Object],[object Object],[object Object],[object Object],[object Object]
Events and Listeners When an event occurs, the generator calls the appropriate method of the listener, passing an object that describes the event Component This object may generate an event Listener This object waits for and responds to an event Event
Listener Interfaces ,[object Object],[object Object],[object Object],[object Object]
Creating GUIs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Creating GUIs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The PushCounter Program
Action Listeners ,[object Object],[object Object],[object Object],[object Object]
GUI Applications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Fahrenheit Program
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

C0 review core java1
C0 review core java1C0 review core java1
C0 review core java1
tam53pm1
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
Shashwat Shriparv
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
M Hussnain Ali
 

Was ist angesagt? (20)

Effective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All ObjectsEffective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All Objects
 
Generics
GenericsGenerics
Generics
 
C0 review core java1
C0 review core java1C0 review core java1
C0 review core java1
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Effective Java - Methods Common to All Objects
Effective Java - Methods Common to All ObjectsEffective Java - Methods Common to All Objects
Effective Java - Methods Common to All Objects
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
M C6java2
M C6java2M C6java2
M C6java2
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
 
My c++
My c++My c++
My c++
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Features
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
Comparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussionComparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussion
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 

Andere mochten auch (7)

JavaYDL20
JavaYDL20JavaYDL20
JavaYDL20
 
Ap Power Point Chpt9
Ap Power Point Chpt9Ap Power Point Chpt9
Ap Power Point Chpt9
 
First Principles Of Cs Instruction
First Principles Of Cs InstructionFirst Principles Of Cs Instruction
First Principles Of Cs Instruction
 
Lecture 4 recursion
Lecture 4    recursionLecture 4    recursion
Lecture 4 recursion
 
Recursion Lecture in Java
Recursion Lecture in JavaRecursion Lecture in Java
Recursion Lecture in Java
 
Ap Power Point Chpt1
Ap Power Point Chpt1Ap Power Point Chpt1
Ap Power Point Chpt1
 
Internet principles of operation
Internet principles of operationInternet principles of operation
Internet principles of operation
 

Ähnlich wie Ap Power Point Chpt5 (20)

Interfaces .ppt
Interfaces .pptInterfaces .ppt
Interfaces .ppt
 
Interfaces.ppt
Interfaces.pptInterfaces.ppt
Interfaces.ppt
 
Oops
OopsOops
Oops
 
C# interview
C# interviewC# interview
C# interview
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java basics
Java basicsJava basics
Java basics
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Hemajava
HemajavaHemajava
Hemajava
 
Java mcq
Java mcqJava mcq
Java mcq
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Ap Power Point Chpt5

  • 1. Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions for AP* Computer Science by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by Addison-Wesley Presentation slides are copyright 2002 by John Lewis, William Loftus, and Cara Cocking. All rights reserved. Instructors using the textbook may use and modify these slides for pedagogical purposes. *AP is a registered trademark of The College Entrance Examination Board which was not involved in the production of, and does not endorse, this product.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Static Methods Because it is static, the method can be invoked as: value = Helper.triple (5); public static int triple (int num) { int result; result = num * 3; return result; } class Helper
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. Interfaces public interface Doable { public void doThis(); public int doThat(); public void doThis2 (double value, char ch); public boolean doTheOther (int num); } None of the methods in an interface are given a definition (body) interface is a reserved word A semicolon immediately follows each method header
  • 24.
  • 25. Interfaces public class CanDo implements Doable { public void doThis () { // whatever } public void doThat () { // whatever } // etc. } implements is a reserved word Each method listed in Doable is given a definition
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 39.
  • 40.
  • 41.
  • 42. Events and Listeners When an event occurs, the generator calls the appropriate method of the listener, passing an object that describes the event Component This object may generate an event Listener This object waits for and responds to an event Event
  • 43.
  • 44.
  • 45.
  • 47.
  • 48.
  • 50.