Académique Documents
Professionnel Documents
Culture Documents
Objectives
• In this lesson, you will learn about:
• Packages in Java
• User-defined packages
• Exploring the java.lang package
• Exploring the java.util package
Packages in Java
• A package is a set of classes that are stored in a directory, which has the same
name as the package name.
• Packages enable you to organize the class files provided by Java.
• Java packages are classified into two categories:
• Java API packages
• Java user-defined packages
User–Defined Packages
• When you write a Java program, you create many classes. You can organize
these classes by creating your own packages.
• The packages that you create are called user-defined packages.
• A user-defined package contains one or more classes that can be imported in a
Java program.
• Creating a user-defined package
• The following syntax shows how to create a user-defined package:
package <package_name>
// Class definition
public class <classname1>
{
// Body of the class.
}
public class <classname2>
{
// Body of the class.}
©NIIT Packages and Streams Lesson 1A / Slide 6 of 30
Java Packages
Class Description
max() Accepts two arguments and returns the public static float
larger of the two values of the arguments. max(float x, float y)
The two arguments should be of same data public static double
type such as float, double, int, or long. max(double x, double y)
public static int
max(int x, int y)
min() Accepts two parameters and returns the public static float
smaller of the two values of the min(float x, float y)
arguments. The two parameters should be public static double
of same data type such as float, double, min(double x, double y)
int, or long. public static int
min(int x, int y)
©NIIT Packages and Streams Lesson 1A / Slide 14 of 30
Java Packages
Class Description
Calendar Provides support for date conversion and can be extended to provide
conversion for specific calendar systems.
Interface Description
Summary
In this lesson, you learned:
Summary (Contd.)
• Some of the classes defined in the java.lang package are :
• The various built-in packages of the Java programming language are:
• Object
• Class
• System
• Wrapper
• Character
• Integer
• Math
• String
• The java.util package provides various utility classes and interfaces that
support date/calendar operations, String manipulation, parsing, and basic
event processing
Summary (Contd.)
• Some of the classes defined in the java.util package are :
• BitSet
• Date
• Calendar
• GregorianCalendar
• Random
• StringTokenizer
• Arrays
• The various interfaces defined in the java.util package are:
• Collection
• List
• Set
• SortedSet