Page 1 of 1

Java API How to read and understand Java API Rate Topic: -----

#1 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Posted 23 July 2009 - 10:20 PM

Fuzzy API Tutorial

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.

Posted Image

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.

Posted Image

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

Posted Image

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.

Posted Image

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:

Posted Image

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:

Posted Image


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)

Posted Image

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)!!

Happy Coding! :D

Is This A Good Question/Topic? 2
  • +

Replies To: Java API

#2 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2636
  • View blog
  • Posts: 15,656
  • Joined: 24-September 08

Posted 27 July 2009 - 06:29 AM

I didn't know you could see it offline... XD
Was This Post Helpful? 1
  • +
  • -

#3 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 900
  • View blog
  • Posts: 3,162
  • Joined: 12-May 09

Posted 27 July 2009 - 06:38 AM

Very helpful - I find it amazing when people are scared of the API. That's one of the great strengths of Java. Any chance you would do a tutorial on javadoc (since it's somewhat related)?
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2636
  • View blog
  • Posts: 15,656
  • Joined: 24-September 08

Posted 27 July 2009 - 07:44 AM

I made one on javadoc. It's in my documentation tutorial. Silly.

I love the API! I spend like 12 hours a day reading it over!
Was This Post Helpful? 0
  • +
  • -

#5 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Posted 05 September 2009 - 11:25 PM

Great to know we have a tutorial on the api, suprising how many people completely ignore it. I'll be linking to this quite a bit in the future now that I know its here :^:

(RTFM of java :D)

This post has been edited by syfran: 05 September 2009 - 11:28 PM

Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Posted 09 September 2009 - 01:40 AM

Aah, I thank you Syfran. Have any input on anything that should get added into it? I know the APi is pretty basic but yeah I also know some other classes can be more complicated and yeah. lol I am almost done with my beginner Java tutorial #10, then going to see about getting the APi, first and second tutorial which are already on here Deleted so i can update them and then Have all of my tutorials linked if you know what I mean. So any input on any of the 3 tutorials I have would be nice on what you think I should update/go into more detail and what not. (Take it to Private Message if you would, don't want to spam this tutorial thread)
Some input from the new people to Java on this would be nice as well.
Good day!

This post has been edited by Fuzzyness: 09 September 2009 - 01:44 AM

Was This Post Helpful? 0
  • +
  • -

#7 Guest_Rusty*


Reputation:

Posted 02 March 2010 - 04:50 AM

I've been searching forever for something like this! I've tried reading the API and making sense of it before, but I think all I wound up reading were the methods (full of abstract words like "buffer", "stream", "block" and "throws", I probably just need to learn some terminology).

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!
Was This Post Helpful? 0

Page 1 of 1