Search code examples
javaterminology

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...


Solution

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