Core Java Tutorial

Define Java

C vs C++ vs Java

Java Virtual Machine

Java First Program

Java Data Types

Java Tokens

Java Keywords

Java Operators

Operator Precedence

Java Type Casting

Java Statement

Java If statement

Java Switch statement

Java Loops

Java Jumping Statement

Java Arrays 1D

Java Arrays 2D

Java Variable Size Array

Java Vector

Java Math Methods

Java String Methods

Java String Buffer

User-Defined Method

Java Method Overloading

Java Class & Object

Java Constructor

Java Inheritance

Java Interface

Java Packages

Java Multi-threading

Exceptional Handling

File Handling

Java Applets

Java DataBase Connectivity

Page Stats

Visitor: 201

Java Packages

A package is a collection of related classes and interfaces providing access protection and namespace management.

Types of Packages

  1. Pre Defined packages
  2. User Defined packages

Pre Defined packages - Java Libraries

  1. java.lang: lang stands for language. This package includes classes for primitive data types, mathematical functions, threads, exceptions etc.
  2. java.util: util stands for Utility. It contain classes such as vectors, hash tables, random numbers, Date and time functions.
  3. java.io: It is a collection of streams and random access files. It provide a wide variety of input and output functions, like read, readLine().
  4. java.awt: awt stands for abstract windowing toolkit. This library contains classes for basic interface components such as windows, events, colors, font and controls such as buttons lists, menu, scroll bars and so on.
  5. java.net: net stands for networking. This package provides classes for communicating with local computers as well as Internet servers. The system requires TCP/IP connection to work with java.net.
  6. java.applet: This package contains classes for creating and implementing applets. Applets need Internet browser to display outputs.

User Defined packages

Creating of a package it involves the following steps:

  1. Declare the package at the beginning of the file. E.g. package <package name>;
  2. Define the class that it to be put in the package & declare it public.
  3. Create a sub-directory under the directory where the main source files are stored.
  4. Store the listing as the class name. java name in the sub-directory
  5. Compile the file javac . This will create a file .class in the file directory.

Example : simple package

package package1;
public class classA
{
	public void display_A()
	{
		System.out.println("Close A");
	}
}
import package1.classA;
class package_test1
{
	public static void main(String argc[])
	{
		classA objectA = new classA();
		objectA.displayA();
	}
}