Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Polymorphism: Wrappers and Interfaces in CMSC 131 Fall 2008 - Prof. Bonnie J. Dorr, Study notes of Computer Science

This document from the cmsc 131 fall 2008 course covers the concepts of polymorphism, wrappers, and interfaces in java. It explains how java provides wrappers for primitive types to enable the use of generic routines and interfaces. The document also discusses the importance of code re-use and polymorphism in object-oriented programming. An example is given of implementing a method using the integer class and adapting cat to implement the comparable interface.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-tdu
koofers-user-tdu 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Java Polymorphism: Wrappers and Interfaces in CMSC 131 Fall 2008 - Prof. Bonnie J. Dorr and more Study notes Computer Science in PDF only on Docsity! 1 CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) Lecture Set #14: Polymorphism Introduction 1. Wrappers 2. Interfaces CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 1 Wrappers  We may want to treat primitives as though they were objects  For example, generic routines can be implemented using interfaces … but they are not usable on primitive types  To overcome this problem, Java provides wrappers for primitive types  Wrappers: classes whose objects contain single values of the “wrapped type”  Wrappers also contain other useful conversion operations (to / from String, etc.)  Wrappers included in java.lang:  Byte  Short  Integer  Long  Float  Double  Character  Boolean 2 CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 2 The Integer Wrapper  The documentation is on-line at http://java.sun.com/j2se/1.5.0/docs/api/  Notes  Immutable  Constructors  Implements Comparable  Documentation says “Comparable<Integer>”  Comparable in Java 5.0 is a interface  Has compareTo method. CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 3 Code Re-use  Many operations recur in programming  sorting  max / min (These operations may apply to strings, numbers, etc.)  Desirable: one implementation!  Less coding  Less likely to have typos  Easier maintenance of code
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved