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:
Field Summary
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.
String(byte[] bytes)
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:

Interfaces
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
Happy Coding!




MultiQuote







|