Top Banner
chool of Computer Science & Information Technology G6DICP - Lecture 14 G6DICP - Lecture 14 Class Libraries Class Libraries
5

School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

Dec 13, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

School of Computer Science & Information Technology

School of Computer Science & Information Technology

G6DICP - Lecture 14G6DICP - Lecture 14

Class LibrariesClass Libraries

Page 2: School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

2

Class LibrariesClass Libraries

Class libraries are pre-defined sets of classes Class libraries are pre-defined sets of classes ready for use by developers.ready for use by developers.

OO programming is largely about making use of OO programming is largely about making use of these classes.these classes.

The class libraries bundled with the JDK and The class libraries bundled with the JDK and included in each VM are called the “Core Java included in each VM are called the “Core Java Classes”Classes”

Class libraries tend to be big - effective use of Class libraries tend to be big - effective use of the documentation is the documentation is essential.essential.

Page 3: School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

3

PackagesPackages

In Java classes may be grouped into “Packages”, In Java classes may be grouped into “Packages”, which have hierarchical names.which have hierarchical names.

The core class libraries are all in packages with The core class libraries are all in packages with the name java.*the name java.*

For example:For example: java.langjava.lang - the main language- the main language java.utiljava.util - useful widgets- useful widgets java.iojava.io - i/o (disk access etc)- i/o (disk access etc) java.textjava.text - sophisticated text manipulation- sophisticated text manipulation java.awtjava.awt - Abstract Windows Toolkit- Abstract Windows Toolkit java.awt.eventjava.awt.event - events for AWT- events for AWT

Page 4: School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

4

Using the Core ClassesUsing the Core Classes

The core class library constitutes the Java API.The core class library constitutes the Java API. Class libraries tend to be big.Class libraries tend to be big. Java core classes (1.4):Java core classes (1.4):

2,723 classes in 135 packages2,723 classes in 135 packages Typically 2-20 methods per class - very roughly 25,000Typically 2-20 methods per class - very roughly 25,000

An understanding of the documentation is thus An understanding of the documentation is thus essentialessential..

http://java.sun.com/docs/http://java.sun.com/docs/ http://java.sun.com/j2se/1.4.2/docs/api/http://java.sun.com/j2se/1.4.2/docs/api/

Page 5: School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.

5

Example ClassesExample Classes

Two important classes from java.lang are:Two important classes from java.lang are: java.lang.Mathjava.lang.Math

Class variables and methodsClass variables and methods The variables contain constants (The variables contain constants ( and and e e ) ) The methods contain mathematical functions The methods contain mathematical functions

(eg Square Root)(eg Square Root) Math is not usually instantiatedMath is not usually instantiated

java.lang.Stringjava.lang.String Instances of String contain textual data.Instances of String contain textual data. Instance methods manipulate that data (eg comparing Instance methods manipulate that data (eg comparing

characters, searching and extracting information).characters, searching and extracting information).