Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.

Slides:



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

 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Java Review Interface, Casting, Generics, Iterator.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Computer Science 209 Software Development Equality and Comparisons.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Inheritance and.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Exam Objective : Legal return types PRESENTED BY : SRINIVAS VG.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Interfaces, Polymorphism Lecture 29, Fri Mar
1 Chapter 21 Generics. 2 Objectives F To know the benefits of generics (§21.1). F To use generic classes and interfaces (§21.2). F To declare generic.
Abstract Classes and Interfaces
Aalborg Media Lab 15-Jul-15 Polymorphism Lecture 12 Chapter 9.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Java Course Outline Kumar Harshit, USW. Course Description Teaches students to program using the Java programming language with the help of the Netbeans.
Chapter 11 Abstract Classes and Interfaces 1. Abstract method New modifier for class and method: abstract An abstract method has no body Compare: abstract.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Inheritance and Polymorphism.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
Chapter 21 Generics 1. Generics - Overview Generic Methods specify a set of related methods Generic classes specify a set of related types Software reuse.
CSC 243 – Java Programming, Spring 2013 March 12, 2013 Week 7, Generics.
CMSC 202 Generics. Nov Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Generics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 5 Generic.
Types in programming languages1 What are types, and why do we need them?
CIS 270—Application Development II Chapter 18-Generics.
CS-2851 Dr. Mark L. Hornick 1 Generic Java Classes Implementing your own generic classes.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
CS212: Object Oriented Analysis and Design
1 CSC241: Object Oriented Programming Lecture No 25.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 19 Generics.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Interfaces and Inner Classes
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 CSC 2053 New from AutoBoxing 3 Before J2SE 5.0, working with primitive types required the repetitive work of converting between the primitive.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
Generics Starring: Rite-Aid Aspirin Co-Starring: CVS Paper Plates.
CS 112 Programming 2 Lecture 06 Inheritance & Polymorphism (1)
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Chapter 15 Abstract Classes and Interfaces.
1 Chapter 21 Generics. 2 Objectives F To use generic classes and interfaces (§21.2). F To declare generic classes and interfaces (§21.3). F To understand.
Java Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
Object Oriented Programming Lecture 2: BallWorld.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 7 Strings Chapter.
Object Oriented Programming
Inheritance, Polymorphism, and Interfaces. Oh My
Computer Science II Exam 1 Review.
Polymorphism, Abstract Classes & Interfaces
Lecture 16 - Interfaces Professor Adams.
FINAL EXAM Final Exam Wednesday, Dec 14: 8: :00 AM (Frny G140)
Midterm Review CSE116A,B.
Presentation transcript:

Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5

Exam will cover Polymorphism and dynamic binding: so review Lecture 11 and run the quiz generator for chapter 9 Interfaces, e.g. Comparable: we reviewed Lecture 17 and 18 and ran the quiz generator for chapter 10 in previous class Exceptions, including text file I/O: review Lecture 23 on your own (we ran the quiz generator for chapter 17 in previous class) Recursion: run quiz generator for chapter 19 Arrays: maybe also run quiz generator for chapter 6

Exam will not cover GUI methods Floating point details Sorting algorithm details Generic types

boxing: new in Java 1.5 Integer I = 10; // 10 is “boxed” Thus conversions between primitive types and wrapper types is automatic when needed

Generic types: new in Java 1.5 Chapter 21 of comprehensive edition of Liang Can declare a generic type in a class, interface or method and specify a concrete type when using it

The Comparable Interface in Java 1.5 public interface Comparable { public int compareTo(T o) } previously there was no and instead of “T o” it was “Object o” is a generic type

Implementing “max” in Java 1.5 public class Max{ public static >E max(E o1, E o2){ if(o1.compareTo(o2) > 0) return o1; else return o2; } } Our old version of “max” could fail at run time because the objects are not of the same class, e.g. o1 references a String and o2 references an Integer This cannot happen with the new version: such an error will get caught at compile time >E both defines a limitation on the class E (it has to implement Comparable ) and says the return type is E the 2 args also need to have the same type E

Implementing Compareable If we want compiler to catch an error when one of the objects references a Date and the other doesn’t, we have to make Date implement Comparable Then the explicit parameter to compareTo must be Date, not Object: this does override the compareTo method of the Object class(?) Now we no longer need a cast – crucial point, as before the cast could have failed at run time