Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is Java API?

I know API is a set of rules and protocols.can anyone explain me with example what is a Java API and its functionality...

like image 254
satheesh.droid Avatar asked Nov 28 '25 21:11

satheesh.droid


2 Answers

You can find Java API here http://download.oracle.com/javase/6/docs/api/index.html

You could say it is the Java library and you can use it like building blocks for your software and that way speed up your development.

For example:

ArrayList is one of the gazilion classes in the API.

import java.util.ArrayList; // We say the old mighty compiler that we want to use this class

// we create an ArrayList object called myList that will hold objects of type Beer
ArrayList<Beer> myList = new ArrayList<Beer>();

Beer b = new Beer();

myList.add(b); // the class ArrayList has a function add, that adds an object(a Beer);

myList.size(); // will give you the size of the ArrayList. 

myList.remove(b); // will remove our beloved Beer :)

If you want to know what else can you do with the ArrayList you should check out the API or when typing myList. CTRL + SPACE will give you all the functions avaible :)

Good luck!

like image 56
Marcus Maxwell Avatar answered Dec 01 '25 11:12

Marcus Maxwell


Exactly what you described, just for the Java language.

Java API is a set of libraries that are found in the standard Java distribution, and is called the JRE (Java Runtime). So, every time you use something like Integer as a class for representing integers, you're using Java's API.

But since Java is so broad, and boundaries between various distributions (Java SE, Java EE, Java ME) aren't always clear at first sight, the terminology "Java API" might be misleading.

So, treat it as the way you communicate your code to Java's libraries.

like image 23
darioo Avatar answered Dec 01 '25 11:12

darioo