Java API

How do you read the API and how can you implement it?

Page 1 of 1

6 Replies - 2248 Views - Last Post: 06 January 2008 - 05:01 PM Rate Topic: -----

#1 jack.in.seoul   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 30-September 07

Java API

Post icon  Posted 05 January 2008 - 05:40 AM

First of all let me say thanks in advance to those who post answers to all the questions taht are posted. It is amazing to see such cooperation in improving the world through coding.

Now for my question...I've finished my first JAVA course on-line and I have some questions about the API. I "understand" that the API is a library of pre-coded modules that help with speeding up the coding of new software but I still don't understand how to read it or apply it. My on-line course was deficient in its ability to get this across in a manner that will help me to become a better programmer. I know that if I have the question that others will also.

If there is anyone out there that can shed some light on how to read and use the API efficiently I would greatly appreciate the insight. This seems to be a really tough part of programming in Java that I don't understand. Reading the code, figuring out what it does and making it work seems to be easier than reading the API and finding and using the code in the API has me stumped.

Thanks again,

Jack

This post has been edited by jack.in.seoul: 05 January 2008 - 05:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Java API

#2 GWatt   User is offline

  • member icon

Reputation: 309
  • View blog
  • Posts: 3,106
  • Joined: 01-December 05

Re: Java API

Posted 05 January 2008 - 08:02 AM

The best way to learn how to use the API is to look at code snippets or tutorials that do something similar to what you're trying to do. Simply reading the API docs and trying to learn how to use everything from that is definitely not the best way to learn.

However, I have found that reading the API docs after knowing what class(es) I'll most likely need is really helpful.
Was This Post Helpful? 0
  • +
  • -

#3 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Java API

Posted 05 January 2008 - 02:03 PM

You use the API docs while you're programming, to look up how to use things that have already been implemented by Sun.

If you use a good IDE like Eclipse, the docs are built-in with the auto completion feature.

The first step to using the API docs is finding the one that matches up with the version of Java you're using.

If you're using Java 6 (1.6), the API docs are available here.

----------------------------------

Say you want to manipulate some Strings. You would open up the API docs, and use the bottom left frame to browse down to the "String" class.

First off, you're going to need to import the "String" class so you can use it's functions in your code. At the top of the "String" class's page, you should see a little chart. Since java.lang.String is at the bottom of your chart, that is what you want to import.

At the very top of your code, add the line import java.lang.String. Now that we've done that, we're going to continue on down the page.

Each class's page usually has a few examples at the top. Further down is a table with the number of ways you can call the "String" constructor.

Underneath that is a list of the methods in the "String" class, that you can use on Strings in your code.

For example, using the "split()" method described in the docs...

test.java
import java.lang.String;

public class test
{
	public static void main(String[] args)
	{
	String one = new String("Hello, I like coding.");

	System.out.println(one);

	String two = one.split(",")[0];

	System.out.println(two);

	String three = one.split(",")[1];

	System.out.println(three);
	}
}


Output
Hello, I like coding.
Hello
 I like coding.



-------------------------------

The docs are not meant to be read and memorized. Most of the things in there, you will never use. Happy coding. :)
Was This Post Helpful? 0
  • +
  • -

#4 jack.in.seoul   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 30-September 07

Re: Java API

Posted 05 January 2008 - 10:49 PM

View PostTom9729, on 5 Jan, 2008 - 02:03 PM, said:

You use the API docs while you're programming, to look up how to use things that have already been implemented by Sun.

If you use a good IDE like Eclipse, the docs are built-in with the auto completion feature.

The first step to using the API docs is finding the one that matches up with the version of Java you're using.

If you're using Java 6 (1.6), the API docs are available here.

----------------------------------

Say you want to manipulate some Strings. You would open up the API docs, and use the bottom left frame to browse down to the "String" class.

First off, you're going to need to import the "String" class so you can use it's functions in your code. At the top of the "String" class's page, you should see a little chart. Since java.lang.String is at the bottom of your chart, that is what you want to import.

At the very top of your code, add the line import java.lang.String. Now that we've done that, we're going to continue on down the page.

Each class's page usually has a few examples at the top. Further down is a table with the number of ways you can call the "String" constructor.

Underneath that is a list of the methods in the "String" class, that you can use on Strings in your code.

For example, using the "split()" method described in the docs...

test.java
import java.lang.String;

public class test
{
	public static void main(String[] args)
	{
	String one = new String("Hello, I like coding.");

	System.out.println(one);

	String two = one.split(",")[0];

	System.out.println(two);

	String three = one.split(",")[1];

	System.out.println(three);
	}
}


Output
Hello, I like coding.
Hello
 I like coding.



-------------------------------

The docs are not meant to be read and memorized. Most of the things in there, you will never use. Happy coding. :)




I understand that they are not to be memorized but it sure would be nice if they were newbee friendly in their explanation of the classes.

A coworker explained it to me this way:

If I have to program something, I can look in the class listing for the classes that fit my needs. I can copy the class code from the API that fits my needs and all I might have to type in is the return value in each class that I need since the API is already coded with the ability to process my requirement. Of course in some instances, I may have to add more than just the return value required but for the majority of things needed, this will be all I need.

If I understand this correctly, I could actually write code straight out of the API into a main and just about have everything I need just programming it through the main. I'm not naive enough to think that this is the case but theoretically it could work if the API had everything I needed for code, right?

Thanks

Jack

This post has been edited by jack.in.seoul: 05 January 2008 - 10:54 PM

Was This Post Helpful? 0
  • +
  • -

#5 jack.in.seoul   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 30-September 07

Re: Java API

Posted 05 January 2008 - 11:05 PM

I actually figured that out after my final in the last class. However, I had trouble figuring out how to use the code that was presented. (please see my response to the next response to my question)

If there had been some type of documentation that explained how to read and implement the classes presented in newbee terms it would have been more healpfull. My quest here was to present the question and hope for replies that will help both myself and others like me who are still strying to figure out how to use the API to make life easier in coding.

I had tried to find soemtihng in the tutorials but there is nothing and I have looked at the code snippets here on DreamInCode.net (one helll of a site by the way) but it just didn't have enough clear explaination to bridge the gap in my understanding.

You stated:

Quote

However, I have found that reading the API docs after knowing what class(es) I'll most likely need is really helpful.


That is the hard part, figuring out what classes will be usefull. They don't provide a newbee like myself with that detailed explanation that completes the bridge.

Thanks,

Jack
Was This Post Helpful? 0
  • +
  • -

#6 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Java API

Posted 06 January 2008 - 10:15 AM

The API docs are a giant reference sheet provided by Sun, no tutorial necessary. Please explain again what it is you don't understand? :)

Sometimes the API is a little too general for what you're trying to do. That's where Java's inheritance comes in. If you wanted to add an attribute to the String class for example, you could extend it and do just that.

Quote

That is the hard part, figuring out what classes will be usefull. They don't provide a newbee like myself with that detailed explanation that completes the bridge.

The API docs are very explanatory about which classes do what. I can see what you're saying though... sometimes you want to do something, but you can't because you don't know what Java calls it. It's at times like these that I turn to my good friend Google. :^:

This post has been edited by Tom9729: 06 January 2008 - 10:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Java API

Posted 06 January 2008 - 05:01 PM

Read the various trails of the Sun Java tutorial (at Sun's site). It guides you through the API with lots of examples.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1