A package in Java is used to group (or) collection of sub packages, classes, interfaces, enum, annotations and it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. We can easily understand using package.
✓Types of Packages- Built In Packages : JDK and JRE provide different packages like java, lang, awt.
- User Defined Packages : Programmer can create the own package as per requirement.
| Package | Description | |
|---|---|---|
| java.applet | : | Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. |
| java.awt | : | Contains all of the classes for creating user interfaces and for painting graphics and images. |
| java.beans | : | Contains classes related to developing beans -- components based on the JavaBeans™ architecture. |
| java.io | : | Provides for system input and output through data streams, serialization and the file system. |
| java.lang | : | Provides classes that are fundamental to the design of the Java programming language. |
| java.math | : | Provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). |
| java.net | : | Provides the classes for implementing networking applications. |
| java.nio | : | Defines buffers, which are containers for data, and provides an overview of the other NIO packages. |
| java.rmi | : | Provides the RMI package. |
| java.security | : | Provides the classes and interfaces for the security framework. |
| java.sql | : | Provides the API for accessing and processing data stored in a data source (usually a relational database) using the JavaTM programming language. |
| java.text | : | Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages. |
| java.util | : | Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array). |
| javax.crypto | : | Provides the classes and interfaces for cryptographic operations. |
| javax.net | : | Provides classes for networking applications. |
| javax.print | : | Provides the principal classes and interfaces for the JavaTM Print Service API. |
| javax.rmi | : | Contains user APIs for RMI-IIOP. |
| javax.management | : | Provides the core classes for the Java Management Extensions. |
| javax.script | : | The scripting API consists of interfaces and classes that define Java TM Scripting Engines and provides a framework for their use in Java applications. |
| javax.sql | : | Provides the API for server side data source access and processing from the JavaTM programming language. |
| javax.swing | : | Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms. |
| javax.tools | : | Provides interfaces for tools which can be invoked from a program, for example, compilers. |
| javax.transaction | : | Contains three exceptions thrown by the ORB machinery during unmarshalling. |
✓User Defined Package
Programmer (or) Developer can create difference type of Packages. We need to understand that Java uses a File System Directory (FSD) to store them that looks like folders on our computers. These are the packages that are defined by the user. First we create a directory like com.jst then create the JstDemo Class inside the directory with the first statement being the package names.
|
Example of User Defined Packages : package com.jaladhi.jst; public class JstUserDefined { public static void main(String args [ ] ) { System.out.println("Jaladhi Soft Technology (JST)"); } } | Output : Jaladhi Soft Technology (JST) |
| Example of Uder Defined Packages : package com.jst.jaladhi; public class UserDefinedPackage { public static void main(String args[]) { System.out.println("Jaladhi Soft Technology (JST)"); } } | Output : Jaladhi Soft Technology (JST) |
✓java.util.function Package in Java 8
| Interface | Description |
|---|---|
| BiConsumer | Represents an operation that accepts two input arguments and returns no result. |
| BiFunction | Represents a function that accepts two arguments and produces a result. |
| BinaryOperator | Represents an operation upon two operands of the same type, producing a result of the same type as the operands. |
| BiPredicate | Represents a predicate (boolean-valued function) of two arguments. |
| BooleanSupplier | Represents a supplier of boolean-valued results. |
| Consumer | Represents an operation that accepts a single input argument and returns no result. |
| DoubleBinaryOperator | Represents an operation upon two double-valued operands and producing a double-valued result. |
| DoubleConsumer | Represents an operation that accepts a single double-valued argument and returns no result. |
| DoubleFunction | Represents a function that accepts a double-valued argument and produces a result. |
| DoublePredicate | Represents a predicate (boolean-valued function) of one double-valued argument. |
| DoubleSupplier | Represents a supplier of double-valued results. |
| DoubleToIntFunction | Represents a function that accepts a double-valued argument and produces an int-valued result. |
| DoubleToLongFunction | Represents a function that accepts a double-valued argument and produces a long-valued result. |
| DoubleUnaryOperator | Represents an operation on a single double-valued operand that produces a double-valued result. |
| Function | Represents a function that accepts one argument and produces a result. |
| IntBinaryOperator | Represents an operation upon two int-valued operands and producing an int-valued result. |
| IntConsumer | Represents an operation that accepts a single int-valued argument and returns no result. |
| IntFunction | Represents a function that accepts an int-valued argument and produces a result. |
| IntPredicate | Represents a predicate (boolean-valued function) of one int-valued argument. |
| IntSupplier | Represents a supplier of int-valued results. |
| IntToDoubleFunction | Represents a function that accepts an int-valued argument and produces a double-valued result. |
| IntToLongFunction | Represents a function that accepts an int-valued argument and produces a long-valued result. |
| IntUnaryOperator | Represents an operation on a single int-valued operand that produces an int-valued result. |
| LongBinaryOperator | Represents an operation upon two long-valued operands and producing a long-valued result. |
| LongConsumer | Represents an operation that accepts a single long-valued argument and returns no result. |
| LongFunction | Represents a function that accepts a long-valued argument and produces a result. |
| LongPredicate | Represents a predicate (boolean-valued function) of one long-valued argument. |
| LongSupplier | Represents a supplier of long-valued results. |
| LongToDoubleFunction | Represents a function that accepts a long-valued argument and produces a double-valued result. |
| LongToIntFunction | Represents a function that accepts a long-valued argument and produces an int-valued result. |
| LongUnaryOperator | Represents an operation on a single long-valued operand that produces a long-valued result. |
| ObjDoubleConsumer | Represents an operation that accepts an object-valued and a double-valued argument, and returns no result. |
| ObjIntConsumer | Represents an operation that accepts an object-valued and a int-valued argument, and returns no result. |
| ObjLongConsumer | Represents an operation that accepts an object-valued and a long-valued argument, and returns no result. |
| Predicate | Represents a predicate (boolean-valued function) of one argument. |
| Supplier | Represents a supplier of results. |
| ToDoubleBiFunction | Represents a function that accepts two arguments and produces a double-valued result. |
| ToDoubleFunction | Represents a function that produces a double-valued result. |
| ToIntBiFunction | Represents a function that accepts two arguments and produces an int-valued result. |
| ToIntFunction | Represents a function that produces an int-valued result. |
| ToLongBiFunction | Represents a function that accepts two arguments and produces a long-valued result. |
| ToLongFunction | Represents a function that produces a long-valued result. |
| UnaryOperator | Represents an operation on a single operand that produces a result of the same type as its operand. |
✓java.util.stream Package in Java 8
| Interface Summary | |
|---|---|
| Interface | Description |
| BaseStream | Base interface for streams, which are sequences of elements supporting sequential and parallel aggregate operations. |
| Collector | A mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed. |
| DoubleStream | A sequence of primitive double-valued elements supporting sequential and parallel aggregate operations. |
| DoubleStream.Builder | A mutable builder for a DoubleStream. |
| IntStream | A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. |
| IntStream.Builder | A mutable builder for an IntStream. |
| LongStream | A sequence of primitive long-valued elements supporting sequential and parallel aggregate operations. |
| LongStream.Builder | A mutable builder for a LongStream. |
| Stream | A sequence of elements supporting sequential and parallel aggregate operations. |
| Stream.Builder | A mutable builder for a Stream. |
| Class Summary | |
| Class | Description |
| Collectors | Implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc. |
| StreamSupport | Low-level utility methods for creating and manipulating streams. |
| Enum Summary | |
| Enum | Description |
| Collector.Characteristics | Characteristics indicating properties of a Collector, which can be used to optimize reduction implementations. |
✓Package Class
The Package Class is available in java.lang package. The Package Class provides methods to get information about the specification and implementation of a package.
|
Example of Package Class : package com.jaladhi.jst; public class PackageInformation { public static void main(String args[]) { Package p=Package.getPackage("java.lang"); System.out.println("Package Name : " + p.getName()); System.out.println("Specification Title : " + p.getSpecificationTitle()); System.out.println("Specification Vendor : " + p.getSpecificationVendor()); System.out.println("Specification Version : " + p.getSpecificationVersion()); System.out.println("Implementaion Title : " + p.getImplementationTitle()); System.out.println("Implementation Vendor : " + p.getImplementationVendor()); System.out.println("Implementation Version : " + p.getImplementationVersion()); System.out.println("Is Sealed : " + p.isSealed()); } } |
Output : Package Name : java.lang Specification Title: Java Platform API Specification Specification Vendor: Oracle Corporation Specification Version: 1.8 Implementaion Title: Java Runtime Environment Implementation Vendor: OpenLogic-OpenJDK Implementation Version: 1.8.0-272 Is Sealed : false |
| Example of Package Class : package com.jaladhi.jst; public class PackageInformation { public static void main(String args[]) { Package p = Package.getPackage("java.util"); System.out.println("Package Name : " + p.getName()); System.out.println("Specification Title : " + p.getSpecificationTitle()); System.out.println("Specification Vendor : " + p.getSpecificationVendor()); System.out.println("Specification Version : " + p.getSpecificationVersion()); System.out.println("Implementaion Title : " + p.getImplementationTitle()); System.out.println("Implementation Vendor : " + p.getImplementationVendor()); System.out.println("Implementation Version : " + p.getImplementationVersion()); System.out.println("Is Sealed : " + p.isSealed()); } } |
Output : Package Name : java.util Specification Title: Java Platform API Specification Specification Vendor: Oracle Corporation Specification Version: 1.8 Implementaion Title: Java Runtime Environment Implementation Vendor: OpenLogic-OpenJDK Implementation Version: 1.8.0-272 Is Sealed : false |