Class Libraries. Readings and References. Java fundamentals. Java class libraries and data structures. Reading. Other References

Similar documents
Java Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering

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

Java Collections. Wrapper classes. Wrapper classes

Java Collections. Engi Hafez Seliem

MIT AITI Lecture 18 Collections - Part 1

The Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

Interfaces, collections and comparisons

Java Collections Framework

CONTAİNERS COLLECTİONS

Collections Questions

Java Collections Framework: Interfaces

Java Collections Framework reloaded

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

COURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE

Object-Oriented Programming with Java

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

Sets and Maps. Part of the Collections Framework

CS2110: Software Development Methods. Maps and Sets in Java

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013

JAVA SYLLABUS FOR 6 WEEKS

Software 1 with Java. Recitation No. 6 (Collections)

Arrays. CSE 142, Summer 2002 Computer Programming 1.

Lecture 16: Case Study: The Java Collections API

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

Unit5: Packages and abstraction

CS Programming Language Java. Fall 2004 Sept. 29

CSC 1214: Object-Oriented Programming

G51PRG: Introduction to Programming Second semester

CS11 Java. Winter Lecture 8

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?

Topic 10: The Java Collections Framework (and Iterators)

Le L c e t c ur u e e 8 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Collections

Computer Science II (Spring )

What is the Java Collections Framework?

Generic classes & the Java Collections Framework. *Really* Reusable Code

USAL1J: Java Collections. S. Rosmorduc

Collections, Maps and Generics

Chapter 10 Collections

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one

JAVA. Duration: 2 Months

CSCI Object Oriented Design: Java Review Execution, I/O and New Features George Blankenship. Java Review: Execution, IO & Java 5

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Objects and Iterators

1Z Java SE 5 and 6, Certified Associate Exam Summary Syllabus Questions

COMP 250. Lecture 32. interfaces. (Comparable, Iterable & Iterator) Nov. 22/23, 2017

Object-Oriented Programming and Data Structures

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

ArrayLists. Readings and References. Collections in the Real World. How can we manage lists of objects? Reading. Other References

ArrayLists. CSE 142, Summer 2002 Computer Programming 1.

CS2110: Software Development Methods. Maps and Sets in Java

First Name: AITI 2004: Exam 2 July 19, 2004

Collections. The Java Collections Framework. The Interfaces

Lists using LinkedList

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Tha Java Programming Language

Algorithms. Produced by. Eamonn de Leastar

ROEVER ENGINEERING COLLEGE Elambalur,Perambalur DEPARTMENT OF CSE

Computational Expression

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

System.out.print(); Scanner.nextLine(); String.compareTo();

CSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException

Software 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface

Some examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani. The Collection Framework

Generics Collection Framework

ABSTRACT DATA TYPES: COLLECTIONS, LISTS, SETS, MAP, QUEUES. Thursday, June 30, 2011

Introduction to Computer Science I

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Building Java Programs

Strings and Arrays. Hendrik Speleers

Exceptions. When do we need exception mechanism? When and why use exceptions? The purpose of exceptions

CMSC 202H. Containers and Iterators

Core JAVA Training Syllabus FEE: RS. 8000/-

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Collections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Tirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax

Java Collections Framework. 24 April 2013 OSU CSE 1

Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being-

Model Solutions. COMP 103: Test April, 2013

Unit5: Packages and abstraction. Prepared by: Dr. Abdallah Mohamed, AOU-KW Updated by Mrs. Malak EL-Amir AOU SAB Fall 14-15

CSE1720 Delegation Concepts (Ch 2)

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Section Lists and Sets

CS Ananda Gunawardena

COM1020/COM6101: Further Java Programming

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

SUMMARY INTRODUCTION COLLECTIONS FRAMEWORK. Introduction Collections and iterators Linked list Array list Hash set Tree set Maps Collections framework

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

13 A: External Algorithms II; Disjoint Sets; Java API Support

Frameworks. CS151 Chris Pollett Oct. 26, 2005.

Pieter van den Hombergh Richard van den Ham. February 8, 2018

CIS 265 Exam 2 First Name Last Name

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

Today. Book-keeping. Exceptions. Subscribe to sipb-iap-java-students. Collections. Play with problem set 1

Transcription:

Reading Readings and References Class Libraries CSE 142, Summer 2002 Computer Programming 1 Other References» The Java tutorial» http://java.sun.com/docs/books/tutorial/ http://www.cs.washington.edu/education/courses/142/02su/ 16-August-2002 cse142-21-libraries 2002 University of Washington 1 16-August-2002 cse142-21-libraries 2002 University of Washington 2 Java fundamentals Object oriented programming» classes and objects» interfaces and inheritance» constructors, methods, variables The Java language» types, expressions» control flow» exceptions Development tools» editors, compiler, Java virtual machine 16-August-2002 cse142-21-libraries 2002 University of Washington 3 Java class libraries and data structures ArrayLists» representative of the many Collection types Arrays» can hold primitive types directly Input and Output» we just looked at the tip of the iceberg with this package 16-August-2002 cse142-21-libraries 2002 University of Washington 4

There's more, much more... Essential Classes» Collections and Internationalization Advanced GUI Building» Swing, 2D Graphics, Sound, and JavaBeans Networking and Connectivity» JDBC, RMI, IDL, Servlets, and Security Packaging» JAR and the Extension Mechanism Advanced Language Topics» Java Native Interface and Reflection 16-August-2002 cse142-21-libraries 2002 University of Washington 5 Collection interface Collection Interfaces, Implementations, and Algorithms From Thinking in Java, page 462 16-August-2002 cse142-21-libraries 2002 University of Washington 6 java.util.collection Interface Collection is the root interface in the collection hierarchy» A collection represents a group of objects (the elements of the collection)» Some collections allow duplicate elements and others do not» Some collections are ordered and others are unordered Collection interface methods Defines two fundamental methods» boolean add(object o)» Iterator iterator() These two methods are enough to define the basic behavior of a collection An Iterator lets you step through the elements in the Collection without knowing the index 16-August-2002 cse142-21-libraries 2002 University of Washington 7 16-August-2002 cse142-21-libraries 2002 University of Washington 8

Iterator interface Iterator Interface Iterator ListIterator 16-August-2002 cse142-21-libraries 2002 University of Washington 9 Defines three fundamental methods» Object next()» boolean hasnext()» void remove() (optional operation) These three methods provide access to the contents of the collection An Iterator knows position within collection Each call to next() gets the next element from the collection 16-August-2002 cse142-21-libraries 2002 University of Washington 10 Iterator Position with next() Example - SimpleCollection public void processcollection(collection c) { System.out.println(c.getClass().getName()); for (int i=9; i >= 0; i--) { c.add(i + " * " + i + " = "+i*i); Iterator iter = c.iterator(); while (iter.hasnext()) { System.out.println(iter.next()); 16-August-2002 cse142-21-libraries 2002 University of Washington 11 16-August-2002 cse142-21-libraries 2002 University of Washington 12

Comparable and Comparator interfaces Comparable Comparator 16-August-2002 cse142-21-libraries 2002 University of Washington 13 Comparable and Comparator interfaces java.lang.comparable» Imposes a total ordering on the objects of each class that implements it» This ordering is referred to as the class's natural ordering, and the class's compareto() method is referred to as its natural comparison method java.util.comparator» Defines a comparison function, which imposes a total ordering on some collection of objects» Comparators can be passed to a sort method (such as Collections.sort) to allow precise control over the sort order» Comparators can also be used to control the order of certain data structures (such as TreeSet or TreeMap) 16-August-2002 cse142-21-libraries 2002 University of Washington 14 Comparable Example public class Vehicle implements Comparable, Cloneable {... /** * Compares this object with the specified object for order, based on the * vehicle identification number. * @param o the other Vehicle object * @return a negative integer, zero, or a positive integer as this * object is less than, equal to, or greater than the specified object. */ public int compareto(object o) { Vehicle other = (Vehicle)o; if (this.vin < other.vin) { return -1; else if (this.vin > other.vin) { return +1; else { return 0; 16-August-2002 cse142-21-libraries 2002 University of Washington 15 Comparator example import java.util.*; import hw6.*; public class CompareByRoute implements Comparator { /** * This method compares two TransitBus objects based on their route * number. This is the only method required by the Comparator interface. * @param oa the first object to be compared. Must be a TransitBus. * @param ob the second object to be compared. Must be a TransitBus. * @return a negative integer, zero, or a positive integer as the route * number of the first argument is less than, equal to, or greater than * the route number of the second argument. */ public int compare(object oa, Object ob) { int ra = ((TransitBus)oA).getRoute(); int rb = ((TransitBus)oB).getRoute(); if (ra < rb) { return -1; else if (ra > rb) { return +1; else { return 0;

List and Set interfaces List and Set Collection List Set public interface List extends Collection» An ordered collection (also known as a sequence)» User can store and access elements by their integer index and search for elements in the list» Lists typically allow duplicate elements public interface Set extends Collection» A collection that contains no duplicate elements and at most one null element» Models the mathematical set abstraction 16-August-2002 cse142-21-libraries 2002 University of Washington 17 16-August-2002 cse142-21-libraries 2002 University of Washington 18 Concrete classes that implement List ArrayList and LinkedList ArrayList List LinkedList ArrayList» fast access to any element in the List by index» implemented with an array of Objects, ie, Object[]» automatically increases array size when needed» add at the end is fast, but add in the front requires copying the entire array to make room LinkedList» fast insert and delete at any point in a list» slow if you want to access elements by index 16-August-2002 cse142-21-libraries 2002 University of Washington 19 16-August-2002 cse142-21-libraries 2002 University of Washington 20

Concrete classes that implement Set HashSet and TreeSet HashSet Set TreeSet HashSet» Like all Collections, a HashSet stores objects» This class offers constant time performance for the basic operations (add, remove, contains and size)» No guarantee as to the order of the elements TreeSet» Guarantees that the set will be sorted in ascending element order 16-August-2002 cse142-21-libraries 2002 University of Washington 21 16-August-2002 cse142-21-libraries 2002 University of Washington 22 Map interface Map Map interface public interface Map A class that implements the Map interface provides an object that maps keys to values» a map cannot contain duplicate keys» each key can map to at most one value This is how the property files for the sliding ovals were implemented arg = (String)pMap.get("width"); if (arg!= null) { width = Integer.parseInt(arg); 16-August-2002 cse142-21-libraries 2002 University of Washington 23 16-August-2002 cse142-21-libraries 2002 University of Washington 24

Concrete classes that implement Map Map HashMap TreeMap HashMap HashMap and TreeMap» provides constant-time performance for the basic operations (get and put) TreeMap» guarantees that the map will be in ascending key order» provides guaranteed log(n) time cost for the containskey, get, put and remove operations 16-August-2002 cse142-21-libraries 2002 University of Washington 25 16-August-2002 cse142-21-libraries 2002 University of Washington 26 Swing package Provides all the components needed for building a graphical user interface» package javax.swing and related packages Can build nice looking applications to run on a variety of underlying systems» for example jedit, BusView JTree JMenuBar Swing components JToolBar JComboBox JTextComponent JSplitPane JTabbedPane 16-August-2002 cse142-21-libraries 2002 University of Washington 27

java.net useful packages» Classes for implementing networking applications java.io» System input and output through data streams, serialization and the file system java.awt» Basic classes for creating user interfaces and for painting graphics and images» User interface event classes (mouse, keyboard, ) useful packages javax.accessibility» Defines a contract between user-interface components and an assistive technology that provides access to those components internationalization (java.util, java.text, )» Messages, labels on GUI components, online help, sounds, colors, graphics, icons, dates, times, numbers, currencies, measurements, phone numbers, honorifics and personal titles, postal addresses, page layouts 16-August-2002 cse142-21-libraries 2002 University of Washington 29 16-August-2002 cse142-21-libraries 2002 University of Washington 30 useful packages java.sql» Classes for accessing and processing data in databases java.util.zip» classes for reading and writing the standard ZIP and GZIP file formats java.util.jar» classes for reading and writing the JAR (Java ARchive) file format, which is based on the standard ZIP file format with an optional manifest file 16-August-2002 cse142-21-libraries 2002 University of Washington 31