Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Tolls

Thread: APIs, packages, classes and libraries

  1. #1
    Join Date
    Oct 2016
    Posts
    47
    Rep Power
    0

    Default APIs, packages, classes and libraries

    I am having trouble understanding how the following terms tie in together - "APIs, packages, classes and libraries"

    1. The very top of the following website indicates that an API contains many packages, and each of those packages contain many classes.
    https://docs.oracle.com/javase/8/doc...w-summary.html


    Do APIs contain packages, and each of those packages contain classes?



    2. On the following website, https://docs.oracle.com/javase/8/docs/ if I click on "Other Base Libraries" next to "Beans" and "JMX" I am taken to this webpage
    https://docs.oracle.com/javase/8/doc...html#otherbase At the top of this page it says "Other Base Packages." This seems to imply that libraries and packages are the same thing. Is this true or false?

    3. Also on at the top of https://docs.oracle.com/javase/8/doc...html#otherbase it says "The java.io and java.nio packages provide a rich set of APIs for managing an application's I/O." This implies that APIs are contained inside of packages. Are APIs contained inside of packages?



    Please answer each question individually. This will help me understand all of these terms better.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: APIs, packages, classes and libraries

    API simply stands for Application Programming Interface.
    It's the definition for how a particular piece of code interacts with the outside world, consequently it can sit at various levels.
    I can have a single class that has an API.
    That class can be part of a package that, as a group, has an API consisting of all the various parts.
    And those can sit inside a framework (eg Spring) that again has an API defining how that framework interacts.

    Packages are ways of organising classes so you don't have the whole lot piled into a great mass.

    Libraries aren't really a Java term, even though you do see it, but when it's used it tends to mean a group of related packages. I suppose a bit like a framework? Not so sure about that one.
    SurfMan likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: APIs, packages, classes and libraries

    classes: the blueprint for your objects. When you say you code Java, you are writing classes mostly.
    packages: a way of grouping related classes, very similar to directories of your filesystem. Pro-tip: when coding in Java, packages actually *are* directories.
    libraries: a group of classes in their corresponding packages that "do something". Now, "doing something" is very broad, ranging from utility classes (e.g. Apache Commons, Log4J) to complete frameworks (e.g. Spring, GWT) and anything in between.

    Wikipedia has a good description of what an API is:
    In computer programming, an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building software and applications. A good API makes it easier to develop a program by providing all the building blocks, which are then put together by the programmer.
    Source: https://en.wikipedia.org/wiki/Application_programming_interface
    The API is what is made available to you to write software. This means, if you are creating a business program for example for accounting, you are using Oracle's Java API to do it. If you are creating your own little toolbox for other programmers, like Apache Commons, you use Oracle's API again, but you also develop an API that others can use.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: APIs, packages, classes and libraries

    You beat me to it Tolls. Good answer.

    Soon.....
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Classes disappear from packages
    By McKracken in forum Eclipse
    Replies: 1
    Last Post: 08-26-2014, 11:22 AM
  2. Importing packages and classes
    By tnrh1 in forum New To Java
    Replies: 3
    Last Post: 11-07-2011, 02:35 PM
  3. Replies: 0
    Last Post: 10-31-2010, 08:51 AM
  4. Classes and packages
    By ramesh.8189 in forum New To Java
    Replies: 4
    Last Post: 02-03-2009, 12:33 PM
  5. Replies: 3
    Last Post: 10-12-2008, 02:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •