Packages
Packages
The important rules that we need to follow while using an abstract class in Java are as follows:
Example:
Understanding the real scenario of Abstract class
class TestAbstraction{
s.draw();
}
But there are many differences between abstract class and interface that are
given below.
1) Abstract class can have abstract Interface can have only abstract methods.
and non-abstract methods. Since Java 8, it can have default and static
methods also.
3) Abstract class can have final, non- Interface has only static and final
final, static and non-static variables. variables.
8) A Java abstract class can have class Members of a Java interface are public by
members like private, protected, etc. default.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
Packages in Java
A java package is a group of similar types of classes, interfaces and sub-
packages. Package in java can be categorized into two types i.e. built-in
package and user-defined package.
Types of packages:
Built-in Packages
These packages consist of a large number of classes which are a part of
Java API. Some of the commonly used built-in packages are:
1) java.lang: Contains language support classes(e.g classed which defines
primitive data types, math operations). This package is automatically
imported.
2) java.io: Contains classed for supporting input / output operations.
3) java.util: Contains utility classes which implement data structures like
Linked List, Dictionary and support ; for Date / Time operations.
4) java.applet: Contains classes for creating Applets.
5) java.awt: Contain classes for implementing the components for
graphical user interfaces (like button , ;menus etc).
6) java.net: Contain classes for supporting networking operations.
User-defined packages
These are the packages that are defined by the user. First we create a
directory myPackage Then create the MyClass inside the directory with the first
statement being the package names. Inside a package, you can have Java files
like classes, interfaces, and a package as well (called a sub-package).
Example:
import java.lang.*;
Output:
Area: 78.53981633974483
Length: 13
Binary: 101010
1) Java package is used to categorize the classes and interfaces so that they can be
easily
maintained.