What is the difference between Java API and user defined packages in JAVA

1.The classes contained in the packages of other programs can be easily reused. Is there any other benefits of packages in JAVA.
I also, came across "Packages also provide a way for separating design from coding". Can anyone explain me the above line.

2. What is the difference between Java API and user defined packages in JAVA


  • Neeraj Sharma
    Neeraj Sharma
    As far as I know

    For 2nd question: There is no specific difference between Java API and user defined packages. It is just that when a user creates a package for carrying out a particular task (for example, Biometric scanning) and wants to distribute it to others so that they can directly use the package for similar applications, we call it an API.

    For 1st question: I think that itself is the sole purpose of packages and that is to reuse the classes. As far as separation of design and coding goes, design is just the structure or a blueprint of a class or method in the package definition. We specify the task that is going to be performed by these class definitions of the package by overriding them and writing code in the actual program where we are using the package. That is how you can say that you are separating design from coding.
  • Alok mishra
    Alok mishra
    APIs are like a layer between your code and data to be processed . For example you have created a class -Maxnumber , in which you defined a method -getmax(int[] arr) , which takes an array of integers as parameter and results the largest Number among them and you placed this class in a package 'findmax' . Now ever again if u want to find maximum element from a given array then dont rewrite the logic code just make a new class and import that package - import findmax.* ; , create object of the class Maxnumber , then using that object call the method i.e. getmax(arr2) passing a reference to an array and you'll get the maximum number by using your smallest API . You can give it to others and it'll help them find maximum element of any integer array .
  • Anoop Kumar
    Anoop Kumar
    API are group of classes to do certain job. in general practice you will just all an api via single point of call.
    For example Google for #-Link-Snipped-# . you will use this api by following fashion.
    InputStream barCodeInputStream = new FileInputStream("file.jpg");
    BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);
    LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    In above code you don't have to bother about what the classes are there in api package (.jar file) and how it's done.

    Package/user defined package is just a mean of grouping classes together so developer get to know that this class is belong to this group (package) some times packages are also use to separate layer of project. like action classes in one package and DTO (data transfer objects are in another).
    Developer call these classes individually as required.
  • Alok mishra
    Alok mishra
    Yes its a way of implementing ABSTRACTION

You are reading an archived discussion.

Related Posts

Engineers at Indian Institute Of Technology, Madras (Chennai) have developed a refrigerator that can achieve temperatures as low as -200 degree C, using a single stage vapour compression refrigerator that...
Indian Air Force is conducting Fast Track selection for male and female candidates for Flying Branch Short Service Commission. The event will be organized at Bengaluru, Pune, Chandigarh and Bhopal...
Researchers have devised a bot that uses Brute Force technique to crack the 4 digit pin of smartphones. The bot tries all the possible 4 digit combinations until it unlocks...
Everyone is aware of the introduction of new Android 4.3 OS. I just wanted to know if an update is available for Galaxy series. From what I have gathered from...
Apple is all set to unveil the Retina version of IPad mini later this year as a competition to Google Nexus 7 offering a high resolution display. Apple has planned...