Docsity

Java Application Frameworks and Collections: A Deep Dive, Slides of Java Programming

Partial preview of the text

Download Java Application Frameworks and Collections: A Deep Dive and more Slides Java Programming in PDF only on Docsity!

Application Frameworks

• Java has an extensive collection of application

frameworks, collections of cooperating classes

that can be used in developing applications.

• Chapter 8 emphasizes three such

frameworks—collections, input/output and

GUIs using AWT and Swing.

Expected knowledge

  • Students should not only understand and be able to use the classes described in the text, but must also develop skill in using Java documentation to go beyond the material in the text.

Abstract Collection Types

  • A bag or multiset is an unordered collection of elements that may include duplicates. A bag, in Java the Collection interface, is the least restrictive and most general form of collection.
  • A set is an unordered collection of elements without duplicates.
  • A list is an ordered collection of elements.
  • A map, dictionary or associative array is an unordered collection of key-value pairs.

Methods of Interface Collection

  • add( element )
  • addAll( collection )
  • clear()
  • contains( element)
  • containsAll( collection )
  • isEmpty()
  • iterator()
  • remove( element )
    • removeAll( collection )
    • retainAll( collection )
    • size()

Methods of Interface Map

  • clear()
  • containsKey( k)
  • containsValue( v )
  • entrySet()
  • get( k )
  • isEmpty()
  • keySet()
  • put( k,v )
    • put( map )
    • remove( k )
    • removeAll( collection )
    • size()
    • values()

k = key v = value

Types of Sets

  • A HashSet stores elements in a hash table.
  • A LinkedHashSet is an ordered hash table.
  • A TreeSet stores elements in a balanced binary tree.

Ordering

• An order (technically a partial order) is a

transitive binary relationship between two

objects. Organized by some criteria, if a has a

certain relationship with b and b has the same

relationship with c , then a has that

relationship with c.

• A sorted collection is one that orders its

elements by a particular relationship.

Defining Orders on Objects

• A class can define a natural order among its

instances by implementing the comparable

interface.

• Arbitrary orders among different objects can be

defined by comparators, or classes that by

implement the comparator interface.

• SortedSet and SortedMap are sorted abstract

collections that inherit the functions of sets and

maps respectively.

Java Graphical User Interfaces

  • Java has a GUI framework consisting of several categories of classes:
  • GUI Components ( widgets ) have a characteristic appearance ( look ) and behavior ( feel ).
  • Layout managers package components in windows. (see FlowLayout and BorderLayout )
  • Events and Event Listeners
  • Grapics and Imaging classes

Abstract Windows Toolkit

  • The basic Java GUI toolkit is the Abstract Windows Toolkit (AWT) The Swing package is an extension of AWT to build high quality GUIs.
  • Review the hierarchy of awt at http://java.sun.com/j2se/1.5.0/docs/api/java/awt/package-tree.html to see the wde variety of classes available to build GUI applications.
  • The Java Class hierarchy is a good starting place to understand

Java libraries: http://java.sun.com/j2se/1.5.0/docs/api/overview-tree.html