CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

Slides:



Advertisements
Similar presentations
Big Ideas behind Inheritance. Can you think of some possible examples of inheritance hierarchies?
Advertisements

Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
Overview of Data Structures and Algorithms
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
CMSC 202 Exceptions 2 nd Lecture. Aug 7, Methods may fail for multiple reasons public class BankAccount { private int balance = 0, minDeposit =
Chapter 11 – Interfaces and Polymorphism. Chapter Goals Learn about interfaces Learn about interfaces Convert between class and interface references Convert.
Interfaces and polymorphism Chapter 9. Interfaces  Used to express operations common to more than one purpose.  Example: You want to find the maximum.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter Nine: Interfaces and Polymorphism.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Interfaces and Polymorphism.
Chapter 8 – Interfaces and Polymorphism Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Remote Procedure Call in SR Programming Language By Tze-Kin Tsang 3/20/2000.
Interfaces. Lecture Objectives To learn about interfaces To be able to convert between class and interface references To appreciate how interfaces can.
Chapter 9 Interfaces and Polymorphism. Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Week 4 Recap CSE 115 Fall 2006 Section C. Decoupling Separation of concerns Defining what an object can do, not how it does it.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Threads A thread is a program unit that is executed independently of other parts of the program A thread is a program unit that is executed independently.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
Unit 081 Introduction to Nested Classes Nested classes are classes defined within other classes The class that includes the nested class is called the.
CS 106 Introduction to Computer Science I 04 / 28 / 2010 Instructor: Michael Eckmann.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
ACM/JETT Workshop - August 4-5, Object-Oriented Basics & Design.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Storage & Linkage: Effects on Scope Rudra Dutta CSC Spring 2007, Section 001.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Object Oriented Programming
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CS 106 Introduction to Computer Science I 04 / 20 / 2007 Instructor: Michael Eckmann.
Exceptions. Exception Abnormal event occurring during program execution Examples –Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
Lecture 10 Documentation, Garbage Collection, and Nested Classes/Interfaces.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Defining New Types Lecture 21 Hartmut Kaiser
Chapter 9 Interfaces and Polymorphism. Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
CHAPTER 9 INTERFACES AND POLYMORPHISM Chapter Goals: –To learn about interfaces –To be able to convert between supertype and subtype references –To understand.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Exceptions. Exception  Abnormal event occurring during program execution  Examples Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Object Oriented Programming in Java Habib Rostami Lecture 10.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Chapter 3 Implementing Classes
Lecture 3 John Woodward.
Chapter Goals To be able to declare and use interface types
Java Primer 1: Types, Classes and Operators
Implementing Classes Yonglei Tao.
Road Map Introduction to object oriented programming. Classes
Java Anonymous inner class
Chapter Three - Implementing Classes
Advanced Java Programming
Packages and Interfaces
Advanced Java Programming
Java Remote Method Invocation
Chapter 11 Class Inheritance
Presentation transcript:

CSS446 Spring 2014 Nan Wang

 To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn how to implement helper as inner classes 2

 Upcasting, can convert from a class type to the type of any interface that the class implements (automatically).  Downcasting, interface  classes If the object(max) doesn’t actually refer to a country, a run­time exception will occur. 3

 Invoking Methods on Interface Variables The Java virtual machine locates the correct method by first looking at the class of the actual object, and then calling the method with the given name in that class. 4

 A Measurable interface is used to measuring a single object.  The Comparable inter­face compares two objects. Return a negative number if a should come before b, zero if a and b are the same, and a positive number if b should come before a.  Comparable interface 5

 Once the BankAccount class implements the Comparable interface, can sort bank accounts array with the Arrays.sort method 6

7

A callback is a mechanism for bundling up a block of code so that it can be invoked at a later time. 8

 A class that is declared inside another class is called an inner class.  The inner class is available to all methods of the enclosing class. Execute file: outerclassName$innerclassName.exe 9

 Anonymous object— an object without a name. only used once Using anonymous class if the class is never used again after a single object of it has been constructed. 10

 Testing some of the classes before the entire program has been completed.  providing the same services as another object, but in a simplified manner. 11  declare an interface type with the same methods that the Grade­ Book class provides.  provide a mock implementation that makes some simplifying assumptions  construct an instance of MockGradeBook and use it in the GradingProgram class which manipulates the mockGradeBook.