Per imparare a programmare bisogna programmare



Similar documents
Web Services in Eclipse. Sistemi Informativi Aziendali A.A. 2012/2013

Introduction to JavaFX. Tecniche di Programmazione A.A. 2012/2013

Client-side programming with JavaScript. Laura Farinetti Dipartimento di Automatica e Informatica Politecnico di Torino laura.farinetti@polito.

Database access and JDBC. Tecniche di Programmazione A.A. 2013/2014

Class 32: The Java Collections Framework

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

Data Structures in the Java API

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Data Structures and Algorithms

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

Working with Java Collections

JAVA COLLECTIONS FRAMEWORK

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

LINKED DATA STRUCTURES

Practical Session 4 Java Collections

Chapter 8: Bags and Sets

The Java Collections Framework

Structural Design Patterns Used in Data Structures Implementation

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

Domains and Competencies

Networks and Services

Computer Science. 232 Computer Science. Degrees and Certificates Awarded. A.S. Degree Requirements. Program Student Outcomes. Department Offices

University of Dayton Department of Computer Science Undergraduate Programs Assessment Plan DRAFT September 14, 2011

Evolution of the Major Programming Languages

Java Software Structures

Principles of Software Construction: Objects, Design and Concurrency. Java Collections. toad Fall 2013

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

f...-. I enterprise Amazon SimpIeDB Developer Guide Scale your application's database on the cloud using Amazon SimpIeDB Prabhakar Chaganti Rich Helms

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

CSCI E 98: Managed Environments for the Execution of Programs

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

: provid.ir

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Hybrid and Custom Data Structures: Evolution of the Data Structures Course

Assessment Plan for CS and CIS Degree Programs Computer Science Dept. Texas A&M University - Commerce

Binary Heap Algorithms

C++ Programming Language

AP Computer Science AB Syllabus 1

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

To Java SE 8, and Beyond (Plan B)

Computing Concepts with Java Essentials

Ordered Lists and Binary Trees

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Programming models for heterogeneous computing. Manuel Ujaldón Nvidia CUDA Fellow and A/Prof. Computer Architecture Department University of Malaga

D06 PROGRAMMING with JAVA

Data Structures and Algorithms Lists

Computer Science. Computer Science 207. Degrees and Certificates Awarded. A.S. Computer Science Degree Requirements. Program Student Outcomes

Computer Science. Computer Science 213. Faculty and Offices. Degrees and Certificates Awarded. AS Computer Science Degree Requirements

Lecture 2: Data Structures Steven Skiena. skiena

Java Coding Practices for Improved Application Performance

Java the UML Way: Integrating Object-Oriented Design and Programming

Glossary of Object Oriented Terms

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

Skills for Employment Investment Project (SEIP)

CS Matters in Maryland CS Principles Course

Data Structures and Algorithms

Automatic vs. Manual Code Analysis

Java EE Web Development Course Program

NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

cs2010: algorithms and data structures

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

dictionary find definition word definition book index find relevant pages term list of page numbers

From Raw Data to. Actionable Insights with. MATLAB Analytics. Learn more. Develop predictive models. 1Access and explore data

UAE Bulk System. User Guide

MICHIGAN TEST FOR TEACHER CERTIFICATION (MTTC) TEST OBJECTIVES FIELD 050: COMPUTER SCIENCE

Cours de C++ Utilisations des conteneurs

Cpt S 223. School of EECS, WSU

F-16 Modular Mission Computer Application Software

Geo-Platform Introduction

The C Programming Language course syllabus associate level

Computer Science 1-3 (AP) Syllabus/Online Course Plan

DATA STRUCTURES USING C

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

HIGH PERFORMANCE BIG DATA ANALYTICS

WHITE PAPER DATA GOVERNANCE ENTERPRISE MODEL MANAGEMENT

CMSC 202H. ArrayList, Multidimensional Arrays

Implementing Project Server 2010

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

2! Multimedia Programming with! Python and SDL

Using Object Database db4o as Storage Provider in Voldemort

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

1/20/2016 INTRODUCTION

Transcription:

Per imparare a programmare bisogna programmare Brian Kernighan Java collections framework Commonly reusable collection data structures Abstract Data Type ADTs store data and allow various operations on the data to access and change it ADTs are mathematical models ADTs are extremely useful when designing a complex algorithms ADTs are not classes (well, not quite) Abstract Data Type ADTs are abstract because they specify the operations of the data structure and leave implementation details to later More similar to abstract classes or (whether the language supports them) Note: Not all implementation details can be deferred! 3 4 Why study ADTs? How many of you will actually go out and create your own ADT from scratch? Different ADTs, each one with its own pros and cons Picking the right one for the job is an important step in design! Get your data structures correct first, and the rest of the program will write itself David S. Johnson (winner of Knuth s Prize in 2010) Why study ADTs? The goal is to learn how to learn how to use and create ADTs 5 6 1

Built-in ADT High level languages often provide built in ADTs. E.g.: Standard Template Library (C++) Java Collections Framework (Java) Common Ground Almost every ADT provide a way to add an item remove an item find, retrieve, or access an item Most Collection ADTs provide more possibilities check whether the collection is empty make the collection empty give me a subset of the collection 7 8 A very simple ADT: Santa s Sack Sack s Operations inserttoy(toy) Insert a toy in the sack Duplicates are obviously allowed extracttoy(toy) Remove the given toy from the sack and make a children happy counttoys() Count how many toys actually are stored in the sack 9 10 Santa s Sack Santa s Sack (more efficient) inserttoy( ) counttoys() inserttoy( ) counttoys() extracttoy( ) extracttoy( ) keep track of the number of objects 11 12 2

The lesson ADTs do not specify the details of the implementation BUT Some information about the algorithms is essential to choose the right ADT Very high-level, qualitative information Complexity Java Collections Framework (JCF) Collection an object that represents a group of objects Collection Framework A unified architecture for representing and manipulating collections Such collections are manipulated independent of the details of their representation JCF vs. ADT 13 14 A little bit of history JDK < 1.2 Standard practice: Vector and Hashtable Compatibility with C++ Standard Template Library (STL) Doug Lea s Collections package ObjectSpace Generic Collection Library (JGL) JDK 1.2 Sun drops compatibility with C++ STL Joshua Bloch s JCF (now Chief Java Architect @ Google) A little bit of history Java 5 Introduction of <generics> Clean, safe definition of the Collection Interface Trees, linked lists, stacks, hash tables, and other classes are implementations of Collection Arrays do not implement the Vector redefined to implement Collection 15 16 A little bit of history Doug Lea later developed a concurrency package JCF s Main Elements Infrastructure Interfaces that provide essential support for the collection General-purpose Implementations Primary implementations (basic and bulk) of the collection 17 18 3

Algorithms Algorithms Static methods that perform useful functions on collections, such as sorting a list JCF s Utility Implementations Legacy Implementations The collection classes from earlier releases, Vector and Hashtable, have been retrofitted to implement the collection Convenience Implementations High-performance "mini-implementations" of the collection Wrapper Implementations Add functionality, such as synchronization, to other implementations 19 20 Abstract Implementations Partial implementations (skeletons) of the collection to facilitate custom implementations Infrastructure These form the basis of the framework Some types of collections allow duplicate elements, others do not Some types of collections are ordered, others are unordered The Java platform doesn t provide any direct implementations of the, but provides implementations of more specific sub-, such as Set and List and Maps 21 22 A Collection represents a group of objects known as its elements The is the least common denominator that all collections implement. It is Used to pass collections around to manipulate them when maximum generality is desire Collection extends Iterable A note on iterators An Iterator is an object that enables you to traverse through a collection (and to remove elements from the collection selectively) You get an Iterator for a collection by calling its iterator() method. Several languages supports iterators. E.g., C++, PHP, Python, Ruby, Go public interface Iterator<E> { boolean hasnext(); E next(); void remove(); 23 24 4

Main Interfaces List A more flexible version of an array Queue & Priority Queue The order of arrival does matter, or the urgency Set No order, no duplicate elements A Map is an object that maps keys to values A map cannot contain duplicate keys: each key can map to at most one value Map does not extend Iterable, but it is possible to get an iterator through entryset() Notez bien: Maps do not extend from java.util.collection, but they re still considered to be part of the collections framework 25 26 Collection Family Tree Iterator<E> iterator(); boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); 27 28 Basic Operations generics Iterator<E> iterator(); boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); wildcard Iterator<E> Bulk Operations iterator(); boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); either extends or implements 29 30 5

Iterator<E> iterator(); Map Family Tree boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); Array Operations 31 32 public interface Map<K,V> { V put(k key, V value); V get(object key); V remove(object key); boolean containskey(object key); boolean containsvalue(object value); void putall(map<? extends K,? extends V> m); Basic Operations public interface Map<K,V> { V put(k key, V value); V get(object key); V remove(object key); boolean containskey(object key); boolean containsvalue(object value); Bulk Operations void putall(map<? extends K,? extends V> m); 33 34 Collection Views public Set<K> keyset(); public Collection<V> values(); public Interface Set<Map.Entry<K,V>> for entryset elements entryset(); public Set<K> keyset(); public Collection<V> values(); public Set<Map.Entry<K,V>> entryset(); public interface Entry { K getkey(); V getvalue(); V setvalue(v value); public interface Entry { K getkey(); V getvalue(); V setvalue(v value); 35 36 6

Licenza d uso Queste diapositive sono distribuite con licenza Creative Commons Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA) Sei libero: di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico, rappresentare, eseguire e recitare quest'opera di modificare quest'opera Alle seguenti condizioni: Attribuzione Devi attribuire la paternità dell'opera agli autori originali e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera. Non commerciale Non puoi usare quest'opera per fini commerciali. Condividi allo stesso modo Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa. http://creativecommons.org/licenses/by-nc-sa/3.0/ 37 38 7