CS313D: ADVANCED PROGRAMMING LANGUAGE

Similar documents
CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

Multiple Choice: 2 pts each CS-3020 Exam #3 (CH16-CH21) FORM: EX03:P

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

Object-Oriented Programming

Visual C# 2012 How to Program by Pe ars on Ed uc ati on, Inc. All Ri ght s Re ser ve d.

CS110D: PROGRAMMING LANGUAGE I

CS111: PROGRAMMING LANGUAGE II

Model 4.2 Faculty member + student Course syllabus for Advanced programming language - CS313D

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Lecture 6: Generics. Lisa (Ling) Liu

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Arrays, Strings and Collections

Computer Programming

Introducing Generics

Object Orientated Analysis and Design. Benjamin Kenwright

CS313D: ADVANCED PROGRAMMING LANGUAGE

ITI Introduction to Computing II

ITI Introduction to Computing II

index.pdf January 21,

CS111: PROGRAMMING LANGUAGE II

Learning to Program in Visual Basic 2005 Table of Contents

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Introduction to Programming Using Java (98-388)

Exam Duration: 2hrs and 30min Software Design

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java.

CS313D: ADVANCED PROGRAMMING LANGUAGE

Deitel Series Page How To Program Series

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun

An Introduction to Collections, Generics, and the Timing Class

Compiler construction

IT 374 C# and Applications/ IT695 C# Data Structures

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Chapter 5 Object-Oriented Programming

CS110D: PROGRAMMING LANGUAGE I

CS313D: ADVANCED PROGRAMMING LANGUAGE

Tentative Teaching Plan Department of Software Engineering Name of Teacher Dr. Naeem Ahmed Mahoto Course Name Computer Programming

CS111: PROGRAMMING LANGUAGE II

Chapter 10. Learning Objectives

Collections, Maps and Generics

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank

CS313D: ADVANCED PROGRAMMING LANGUAGE

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Programming Language Concepts, CS2104 Lecture 7

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

Object oriented programming C++

ITI Introduction to Computing II

Computer Programming

Advanced Programming Methods. Lecture 9 - Generics, Collections and IO operations in C#

Algorithms & Data Structures

Inheritance, Polymorphism, and Interfaces

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

Structured Programming Using C++ Lecture 10 : Graphics Programming with the Dark GDK Library. Dr. Amal Khalifa. Lecture Contents:

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Introduction to Programming (Java) 4/12

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Language-based Protection: Solution

by Pearson Education, Inc. All Rights Reserved. 2

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Lecture Notes on Tries

G52CPP C++ Programming Lecture 13

Java Fundamentals (II)

Overview. ITI Introduction to Computing II. Interface 1. Problem 1. Problem 1: Array sorting. Problem 1: Array sorting. Problem 1: Array sorting

System.Collections.Generic.SortedSet: who needs another collection anyway?

Supporting Class / C++ Lecture Notes

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Agenda: Discussion Week 7. May 11, 2009

Introduction To C#.NET

Visual C# 2008 How to Program, 3/E Outline

Chapter 14. Collections

Chapter 3 Function Overloading

COEN244: Class & function templates

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Your first C++ program

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

abstract binary class composition diamond Error Exception executable extends friend generic hash implementation implements

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

Introduction & Review

CS250 Final Review Questions

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Visual Basic 2008 How to Program, 4/E Outline

M.CS201 Programming language

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CS4215 Programming Language Implementation

Stream Computing using Brook+

CS 132 Exam #1 - Study Suggestions

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,

VARIABLES AND TYPES CITS1001

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Sorting/Searching and File I/O. Sorting Searching Reading for this lecture: L&L

Transcription:

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 9: Generics & generic Collections

Lecture Contents 2 Introduction Why generics? Generic methods Overloading generic methods Generic classes Generic collections SortedDictionary

Motivation for Generic Methods 3 Overloaded methods are often used to perform similar operations on different types of data. Example: Write a set of overloaded methods to display the elements of an int array, a double array and a char array, respectively.

4

How to use? 5 calls to DisplayAr ray method are identical. The Compiler matches the method based on its segnature

Generic Method 6 T Any type Type checking Consistent processing

7

8 Tip!!

Type Constraints 9 We can restrict the types that can be used with a generic method or class to ensure that they meet certain requirements known as a type constraint C# provides several kinds of type constraints. A class constraint indicates that the type argument must be an object of a specific base class or one of its subclasses. An interface constraint indicates that the type argument s class must implement a specific interface.

IComparable<T> Interface 10 It s possible to compare two objects of the same type if that type implements the generic interface IComparable<T> all IComparable<T> objects are guaranteed to have a CompareTo(object) IComparable<T> objects can be used with the sorting and searching methods of classes in the System.Collections.Generic not all types implement interface IComparable<T> the structures in the Framework Class Library that correspond to the simple types all implement this interface

Finding Maximum 11 an interface constraint: requires each of the method s arguments to be of type IComparab le<t>

12

Overloading Generic Methods 13 A generic method may be overloaded. Each overloaded method must have a unique signature. A class can provide two or more generic methods with the same name but different method parameters. A generic method can be overloaded by nongeneric methods with the same method name. When the compiler encounters a method call, it searches for the method declaration that best matches the method name and the argument types specified in the call.

Generic Classes 14 With a generic class, you can use a simple, concise notation to indicate the actual type(s) that should be used in place of the class s type parameter(s). At compilation time, the compiler ensures your code s type safety, and the runtime system replaces type parameters with type arguments to enable your client code to interact with the generic class.

Example 15 generic Stack class, (e.g., Stack of double, Stack of int, Stack of char, Stack of Employee

16

17

18

Stack app 19

20

21

22

23

24

Generic Collections 25 Namespace System.Collections contains collections that store references to objects. Most new apps should use the collections in the System.Collections.Generic namespace, which contains generic classes such as the List<T> and Dictionary<K, V> classes you learned previously to store collections of specific types. dr. Amal Khalifa, Spr 17

26 Generic collections dr. Amal Khalifa, Spr 17

Introduction 27 A dictionary is the general term for a collection of key value pairs. A hash table is one way to implement a dictionary. The.NET Framework provides several implementations of dictionaries, both generic and nongeneric, all of which implement the IDictionary interface dr. Amal Khalifa, Spr 17

Generic Class SortedDictionary 28 The entries in SortedDictionary are sorted in the tree by key. When the key implements generic interface IComparable<T>, the SortedDictionary uses the results of IComparable<T> method CompareTo to sort the keys. use the same public methods, properties and indexers with classes Hashtable dr. Amal Khalifa, Spr 17

Example 29 Find the number of word occurrences in a line of text. dr. Amal Khalifa, Spr 17

Example 30 does not use a hash table, but instead stores its key value pairs in a binary search tree. dr. Amal Khalifa, Spr 17

31 dr. Amal Khalifa, Spr 17

32 dr. Amal Khalifa, Spr 17

33 Tip dr. Amal Khalifa, Spr 17

34 Text Book Chapter 20: 20.1 20.6 Chapter 21: 21.5

Case Study 35