Java API How to read and understand Java API
Posted 23 July 2009 - 10:20 PM
Many people donít like to read the API, I am unsure why they donít like to do that, just about any question they ask us here on D.I.C. could be answered in the API if they looked and experimented a little bit. I have come to the conclusion about a couple possibilities:
1. Think you can only get to the API online. That depends really. You can download the docs if it is not already downloaded. Then you can find them under the Java file in the Program Files in the local c: drive. Open docs, then open API, and there you have it, the entire API in html files that can be run from a source with no internet. Here you go!
2. People are just so lazy that they wish to attempt to have people give them answers instead of doing a little bit of research on it themselves. Yes very buyable, I too am SUPER lazy and attempt to do the easiest way all the time, lucky for us lazy people, the easiest way is usually the most efficient!
3. They donít know how to read the API. . . crazy I know but it happens more often then you would believe, how to properly read the API, and sadly enough quite a few beginners donít even know that an API exists!!! CRAZY!!
So in my solution I have come to this: Show them how to read the API.
We will use the String API as an example, the fact that your reading this means you have internet and so I think it is safe to say you can follow me by opening the String class from Sunís online API - String Class. This tutorial will be easier to follow if you open it and follow a long, but should you not wish to open it then I have shown examples of each section from the same String Class in the API.
When you first open it you run into the heading of the Class, it consists of the class Hierarchy and the Interfaces that it can use should your class be implementing it.
**Notice**One thing that you should know, it that the Object class is the Super Class of everything!! Everything is an object and an Object can be anything! This is why in the hierarchy you will many times see java.lang.Object and then everything broken down from there.
Once you get past the header of the Class, you will notice a section that is pretty much the intro to the class. It will usually give a couple example on what you could do with the code and how to implement certain things. It is still your part in getting creative to user a Class to its full potential.
Following the General Information of the class in the API you get to some tables with highlighted blue words and baaah. Basically here is the first one:
This is a individual list of all the fields that your class will inherit should it implement one of the interfaces, the API is pretty self explanatory so not much to tell but look over classes and become familiar with the layout
After that you will find a table of the Class Constructor, this is all the ways that you can create and object of this class with a definition of what exactly youíre creating. In the Constructor, you will notice how it has words in the Ď()í part of the constructor.
Those would be parameters or some people would call them arguments. You MUST have them in order to create the object correctly. It will tell you the type of variable you need; you do not have to use the same words as they do, just the same type.
byte means you need an array of byte objects. Must use one
bytes This is just a variable name, you can change it to ďJohnnyQĒ if you feel like it.
Deprecated Ė means that it is outdated, it may not compile if you use it, and if you do use it and the IDE accepts it, you will get a notice of X-lint deprecated. You can use it, however, in a future update or version of Java, your program may not work anymore properly because the program may not read it.
After you pass the constructor Summary you will reach all of the methods. This is a list in a table format like everything else, that is a list of all the methods what they need for parameters and if they return anything. Heading looks like this:
After you finish getting through that table you have 3 more, which give the Details and Descriptive Explanations and practical examples for each item in the Field Summary, Constructor Summary, and the Method Summary. It is bluntly called ď%s FieldĒ
They will look like this:
Upon input from mostyfriedman; I would agree that I need to add something that can explain an interface. First off, they are VERY similar to a regular Class in the API, however read a little differently though. For this example, I will use the common actionListener Class.
Here is the class, (because it is so small in the API but yet such an important class)
The first thing that you will see below the heading is a Superinterface, like a Regular Class, there is a Hierarchy, this is in the form of the Superinterface. EventListener is the parent class to this actionListener Class.
Then it will show you the Subinterfaces and the Implementing Class. Because you extend a class with actionListener, you will get to use all those methods from all of those classes, without importing each individual class!
The rest you are familiar with, the only difference this time, is the Method Summary, still has a list of the Methods, but because this is an interface, you HAVE to have that method in the class, otherwise it will not compile correctly. The method Detail section does the same explaining each method in a little more detail.
I thank you for your time, should you have a question or a comment to leave please don't quote this whole post, simply ask it Feel free to look for my Java Basic Tutorials that are coming very shortly (if not already out)!!
Replies To: Java API
Posted 05 September 2009 - 11:25 PM
(RTFM of java )
This post has been edited by syfran: 05 September 2009 - 11:28 PM
Posted 09 September 2009 - 01:40 AM
Some input from the new people to Java on this would be nice as well.
This post has been edited by Fuzzyness: 09 September 2009 - 01:44 AM
Posted 02 March 2010 - 04:50 AM
I guess as a beginner I just don't know which part of the API I should START with. I was reading through the java.io package which seems pretty intimidating, as I read in some other forum that it was a good place to start.
I really like programming, but the implicit dependence upon the API almost turned me away from it. Thank you for posting this!