12
Using the Java API http://java.sun.com/j2se/1.3/ docs/api/

Using the Java API

  • View
    242

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Using the Java API

Using the Java API

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

Page 2: Using the Java API

Overview

Classe

s

Package

s

View

s

Main Information

Area

Page 3: Using the Java API

General approach

• If you know the name of the package, click it in the upper left panel; or click All Classes

• Click on the class in the lower left panel

• Scroll in the right pane to find the summary of the field, method, or constructor you want– Or just read the general description

• For more information, click the link in the summary to go to the detailed information

Page 4: Using the Java API

The Packages panel

• Choose the package you are interested in

• Or, choose All Classes• Classes in java.lang

are automatically imported into every program--you don’t have to do it yourself

Page 5: Using the Java API

The Classes panel

• This panel shows both classes and interfaces

• We haven’t yet talked about interfaces

• Note that some classes have names similar to primitive types (Boolean, Byte, Character)

Page 6: Using the Java API

The links bar

• Overview is where you start out

• Index is handy for looking up methods

• Help is the obvious• If you don’t like frames, you can choose

NO FRAMES• Deprecated methods are those that have been

replaced by better methods and should not be used

Page 7: Using the Java API

The main information area

• General description of the class• Field summary• Constructor summary• Method summary• Field detail• Constructor detail• Method detail

• In each case, the “summary” is the first sentence of the “detail”

Page 8: Using the Java API

Reading the method descriptions I

• An example from the String class:– public char charAt(int index)

• Returns the character at the specified index

– public means accessible from anywhere

– char is the return type

– charAt is the name of the method

– int is the type of parameter expected

– index is just a suggestive name– Example use: char firstChar =

myStr.charAt(0);

Page 9: Using the Java API

Reading the method descriptions II• Another example from the String class:

– public static String valueOf(int i)• Returns the string representation of the int argument.

– public means accessible from anywhere

– static means this is a class method (see use below)

– String is the return type, and is a hyperlink

– valueOf is the name of the method

– int is the type of parameter expected

– i is just a suggestive name

– Example use: String numeral = String.valueOf(m / n);

Page 10: Using the Java API

How was this documentation produced?

• All Java documentation was produced by the javadoc program from javadoc (or just doc) comments in the source code

• Your doc comments can be used in the same way to produce professional-looking documentation

• The Interface menu item in BlueJ does the same basic thing as javadoc– Like most things in BlueJ, fancy features have

been omitted in the interests of simplicity

Page 11: Using the Java API

Value of the API

• Java 1.2 gives you 60 packages containing 1781 classes and interfaces, 3538 fields, 2337 constructors, and 15060 methods

• You can only learn a small fraction of these

• When you learn the kinds of things that are in the API, and learn to find your way around in it, you become a far more effective and efficient programmer

• A good craftsman knows his/her tools

Page 12: Using the Java API

The End