Java Generics Lecture 17 CS2110 – Spring 2017

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Java 2 Programming Lecture 5 Array and Collections.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming Overview of Week 2 25 January Ping Brennan
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.
Lecture 20 Arrays and Strings
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
String class  Construct a string  String str = new String(“welcome”);  Char[] charr = {‘G’, ‘o’, ‘o’, ‘d’};  String mes = new String(charr);  A full.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Primitive Types CSE 115 Spring 2006 April 3 &
ARRAYS In this Lecture, we will try to develop understanding of some of the relatively complex concepts. The following are explained in this lecture with.
CS107 Introduction to Computer Science Java Basics.
 The general subject of comparing objects, or object references, can be introduced concretely with strings.  Recall that String is a class, and so strings.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
1 CSC 222: Computer Programming II Spring 2005 Java interfaces & polymorphism  Comparable interface  defining an interface  implementing an interface.
CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
GENERICS AND THE JAVA COLLECTIONS FRAMEWORK Lecture 16 CS2110 – Fall 2015 Photo credit: Andrew Kennedy.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
A: A: double “4” A: “34” 4.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Introduction to programming in java Lecture 21 Arrays – Part 1.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
1 Section 11.4 Java Interfaces – The Implementation Perspective Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 7 Strings Chapter.
Classes (Chapter ) Classes (Chapter ) Data with natural operations Classes Using Classes.
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Relational Operator and Operations
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
CS2006- Data Structures I Chapter 5 Linked Lists I.
Introduction to Computer Science / Procedural – 67130
Chapter 20 Generic Classes and Methods
Java Generics Lecture 14 CS2110 – Fall 2016
Interfaces I once attended a Java user group meeting where James Gosling (Java's inventor) was the featured speaker. During the memorable Q&A session,
Primitive Types Vs. Reference Types, Strings, Enumerations
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
Review Operation Bingo
Chapter 7: Strings and Characters
Examples of Primitive Values
Programming in C# Comparison (Sorting)
Java Generics Lecture 22 CS2110 – Fall 2018
Part a: Fundamentals & Class String
The compareTo interface
Java Lesson 36 Mr. Kalmes.
String Concatenation Objectives
Java Generics Lecture 22 CS2110 – Fall 2018
Coding Concepts (Data- Types)
Compiler Design First Lecture.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Arrays.
Unit 4 Scientific Notation
Nate Brunelle Today: Strings, Type Casting
The Comparable Interface
Adding and Subtracting Integers
CS150 Introduction to Computer Science 1
TCSS 143, Autumn 2004 Lecture Notes
Building Java Programs
Nate Brunelle Today: Strings, Type Casting
Switch, Strings, and ArrayLists in Java
CS 1054 Introduction to Programming in Java
CS Problem Solving and Object Oriented Programming Spring 2019
Presentation transcript:

Java Generics Lecture 17 CS2110 – Spring 2017 Photo credit: Andrew Kennedy Lecture 17 CS2110 – Spring 2017

Proposals for adding Generics to Java Andrew Meyers Nate Foster Turing Award winner Barbara Liskov Finally appeared in Java 5 (2004). PolyJ Pizza/GJ LOOJ …all based on parametric polymorphism.

Concatenating Lists Suppose we want to concatenate a list of lists into one list. We want the return type to depend on what the input type is. lists 3 8 7 5 6 2 Return this list 3 6 8 7 5 2

Interface Comparable Interface Comparable<T> declares a method for comparing one object to another. interface Comparable<T> { /* Return a negative number, 0, or positive number * depending on whether this is less than, * equal to, or greater than that */ int compareTo(T that); } Integer, Double, Character, and String are all Comparable with themselves