Using the Java API http java sun comjavase6docsapi

  • Slides: 14
Download presentation
Using the Java API http: //java. sun. com/javase/6/docs/api/

Using the Java API http: //java. sun. com/javase/6/docs/api/

Where’s the API? 2

Where’s the API? 2

Overview s w Vie s e g a k c a P s a

Overview s w Vie s e g a k c a P s a l C s e s n o i t a m r o a e Ar f n I in Ma 3

General approach n n n If you know the name of the package, click

General approach n n n 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 n n Or just read the general description For more information, click the link in the summary to go to the detailed information 4

The Packages panel n n n Choose the package you are interested in Or,

The Packages panel n n n Choose the package you are interested in Or, choose All Classes in java. lang are automatically imported into every program--you don’t have to do it yourself Old snapshots—but the format hasn’t changed 5

The Classes panel n n n This panel shows both classes and interfaces We

The Classes panel n n n 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) 6

The links bar n n n Overview is where you start out Index is

The links bar n n n 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 7

The main information area n n n n General description of the class Field

The main information area n n n n General description of the class Field summary Constructor summary Method summary Field detail Constructor detail Method detail n In each case, the “summary” is the first sentence of the “detail” 8

Reading the method descriptions I n An example from the String class: n public

Reading the method descriptions I n An example from the String class: n public char. At(int index) n n n n Returns the character at the specified index public means accessible from anywhere char is the return type char. At is the name of the method int is the type of parameter expected index is just a suggestive name Example use: char first. Char = my. Str. char. At(0); 9

Reading the method descriptions II n Another example from the String class: n public

Reading the method descriptions II n Another example from the String class: n public static String value. Of(int i) n Returns the string representation of the int argument. n public means accessible from anywhere static means this is a class method (see use below) String is the return type, and is a hyperlink value. Of is the name of the method int is the type of parameter expected i is just a suggestive name n Example use: String numeral = String. value. Of(m / n); n n n 10

How was this documentation produced? n n n All Java documentation was produced by

How was this documentation produced? n n n 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 Blue. J does the same basic thing as javadoc n Like most things in Blue. J, fancy features have been omitted in the interests of simplicity 11

Value of the API n n Version packages classes methods Java 1. 0 8

Value of the API n n Version packages classes methods Java 1. 0 8 212 1545 Java 1. 1 23 504 3851 Java 1. 2 60 1781 15060 Java 1. 3 77 2130 17158 Java 1. 4 135 2738 ? Java 1. 5 and 6 ? ? ? 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 12

Where to find the API docs n On the web: n n http: //java.

Where to find the API docs n On the web: n n http: //java. sun. com/javase/6/docs/api/ On your own computer (if you downloaded them): n C: /Program. Files/Java/jdk 1. 6. 0_01/docs/api/index. html 13

The End Regarding “The Inevitability of e. Books: ” “Did you ride a horse

The End Regarding “The Inevitability of e. Books: ” “Did you ride a horse to work today? I didn’t. I'm sure plenty of people swore they would never ride in or operate a ‘horseless carriage’—and they never did! And then they died. ” http: //chrisyeh. blogspot. com/2009/02/and-then-they-died-inevitability-of. html 14