Introduction of Packages | Types of API Packages | API package | User Defined Package

Описание к видео Introduction of Packages | Types of API Packages | API package | User Defined Package

In this video, I have explained the basics of package in java i.e. introduction to package in java. Packages in java is a way to collect similar types of classes under one roof. Packages in java may be categorized into two parts:
1. Java API Packages/ Built-in / Library Packages
2. User Defined Packages


Introduction To Package
A package is basically collection of different classes. In other words we can say that package is a way to group variety of classes and/or interfaces together. The grouping is usually done on the basis functionality.

Package gives us following benefits:
1.The classes contained in a package can be used in any program that import that classes.
2.Packages provide a way to “hide” classes.
3.Pcakage also provides a way for separating “design” from “coding”.

Types of Package

Packages are broadly categorized into two ways:
1. API packages
2. User Defined Packages

Java API Packages
Java API (Application Programming Interface) Packages provides a way to group different classes into different packages. The different java API packages are:

Package Name what it contains
1. java.lang Language support classes. These are the classes that java compiler itself uses and therefore the are automatically imported. They include classes for primitive datatype, string, maths functions, threads and exceptions.

2. java.util Language utility classes such as vector, random number, scanner etc.

3. Java.io input/output support classes

4. Java.awt set of classes to implement GUI

5. Java.net classes for networking

6. Java.applet classes for creating and implanting applets.

User System Package

There are two ways to access the classes stored in the package. The first approach is to use fully qualified class name of the class that we want to use.

For example, if we want to refer to the class Color in the awt package, then we may do as follows:
java.awt.Color
If we want to refer the Scanner class in the util package, then we may do so as follows:
java.util.Scanner;

Name Conversions
Packages can be names using the standard java naming rules. By conversion, however, packages being with lowercase letters. This makes it easy for users to distinguish package name from class name.

double y=java.lang.Math.sqrt(x);

Here, lang is the package, Math is the class and sqrt is the function i.e. the method name.

Комментарии

Информация по комментариям в разработке