"If I can't picture it, I can't understand it.". Reference anonymous - gravity https://www.youtube.com/watch?v=cEkILY1h6fA Concrete classes: rules of.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
Inner Classes. Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class Inner classes.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Inner and Anonymous Classes Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and.
CS2110: SW Development Methods Inheritance in OO and in Java Part 1: Introduction Readings: A few pages in Ch. 2 of MSD text introduce this Section 3.3.
Exceptions: Checked versus Unchecked Exceptions.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Piazza Piazza: 037/home Course website:
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Object Oriented Software Development
2-Dec-15 Inner Classes. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class.
Object Oriented Programming.  Interface  Event Handling.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Inheritance and Access Control CS 162 (Summer 2009)
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CS 106 Introduction to Computer Science I 04 / 18 / 2008 Instructor: Michael Eckmann.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Lec 06 Agenda 1/ the 8 rules of Java 2/ Casting primitives 3/ Swing and Threading 4/ Java Event Model. Event api and support for Swing 5/ Swing labs, live.
Agenda Lec05 Exceptions API Reference- and Type-Anonymity Swing Review.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Object Oriented Programming in Java Habib Rostami Lecture 10.
Object-Oriented Programming: Polymorphism Chapter 10.
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Inner Classes.
Events and Event Handling
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
Inner Classes 27-Dec-17.
Sections Inheritance and Abstract Classes
Interfaces Unit 08.
Agenda Lec05 Exceptions API
Lec 06 Agenda 1/ the 6 rules of Java
A tree set Our SearchTree class is essentially a set.
Inner Classes 29-Nov-18.
A tree set Our SearchTree class is essentially a set.
CSE 1030: Implementing GUI Mark Shtern.
Abstract Classes Page
Java Inheritance.
Quizz Results hw1 quizz mean std-dev
Events, Event Handlers, and Threads
Chapter 14 Abstract Classes and Interfaces
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 1-May-19.
Inner Classes 11-May-19.
Inner Classes 18-May-19.
Elipses int... passed into method as int[]
Inner Classes.
Inner Classes 25-Oct-19.
Presentation transcript:

"If I can't picture it, I can't understand it."

Reference anonymous - gravity Concrete classes: rules of fight club Type anonymous : Fight Club - Robert Paulson Dubugger: x-men quicksilver

References Objects are like astronauts.

References Object objDate = new Date(); This date has a reference. The reference is an Object.

Reference Anonymous MyTime myTime = new MyTime(new Date()); The date is reference-anonymous, but we can still get a reference to it myTime.getDate(); new Date(); The date is reference-anonymous and we have no reference to it – it is space-junk and will be garbage collected.

Reference Anonymous Date dat1 = new Date(); Date dat2 = new Date(); dat1 = dat2; The Object originally stored in dat1 is orphaned and becomes space junk.

Java entityMay be a reference?May be an instantiated? Concrete ClassYES Abstract ClassYESNO InterfaceYESNO

Fight Club Rules of Java 1/ Only concrete classes can be instantiated.

Fight Club Rules of Java 1/ Only concrete classes can be instantiated. 2/ Only concrete classes can be instantiated.

Fight Club Rules of Java 1/ Only concrete classes can be instantiated. 2/ Only concrete classes can be instantiated. 3/ The type of any Object must be of type Concrete_class. (corollary to 1 and 2) 4/ References may be concrete, abstract, or interface.

Fight Club Rules of Java 5/ You may create type-anonymous abstract- classes and interfaces by overriding ALL their contract methods when you declare them. 6/ The “type” of a type-anonymous class is $x aka Robert Paulson.

Reflection If your program is written well and adheres to the principals of polymorphism, then you don't really need reflection. However, it's nice to know you have it when testing/debugging though. Very useful when first learning an OO language.

Reflection Reflection allows you to inspect the type (class) of the implicit parameter at runtime. We will use reflection to gain a deeper understanding of polymorphism and the java event model. Every class has a class object which you can access like so: java.util.Date.class, or like so: Class.forName(strFullyQualifiedClass); See reflection example

Reflection Name of Driverimplemnts Implicit param EventListener typeDefined TimeTestOuter ActionListener yesEventListenerOuter In separate java file TimeTestInner ActionListener yesEventListenerInnerIn same java file TimeTestLocal ActionListener yesanonymousSame method TimeTestAnon ActionListener noanonymousinline See inner example

Java Event Model Used to program behavior in GUIs Used extensively in Android.

If a tree falls in a forest and no one is around to hear it, does it make a sound?

Event (onClick) No Event-Listener listening No Catcher Event-Source (Button) No Event Listener

Event (onClick) Event-Listener listening Catcher ready to catch Event-Source (Button) ActionList ener Any Object

Wrong Event

Event source not registered

Event (Action) Event-Listener listening Catcher ready to catch Action- Listener Event-Source (Button) Any Object OnMouse- Listener Event (Mouse)

Step 1/ define the event-listener object and override the appropriate methods ActionListener mActionListener = new ActionListener() public void actionPerformed(ActionEvent e) { //behavior here }}; Step 2/ register (add) the event-listener to the event source. mButton.addActionListener(mActionListener);

Casting Casting down may be done ONLY down the class hierarchy. Casting up is not required because a subclass object may always be stored in a superclass reference (or an interface that it implements).

Inner and Anonymous Classes Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and write procedural-like code. Often times, no one but the enclosing class cares about an object. In this case, you may consider using inner or anonymous classes.

Write a very simple application for a contact manager. The the sake of simplicity, each contact will have a name and a phone number only. The user should be able to create new contacts and diplay all contacts. Create a Latin dictionary with entries for Latin and English equivalents. Store them in a list and allow the user to delete them.

Interfaces A class implements an interface rather than extends it. Any class that implements the interface must override all the interface methods with it's own methods. Interface names often end with "able" to imply that they add to the capabilty of the class. An interface is a contract; it defines the methods

The ColorSelector GUI App

The Leet Translator GUI App