.Trashed 1742732429 Java Packages GeeksforGeeks
.Trashed 1742732429 Java Packages GeeksforGeeks
Java Packages
Last Updated : 04 Feb, 2025
Example:
import java.util.*;
import java.util.Vector;
This imports only the Vector class from the java.util package.
import java.util.*;
This imports all classes and interfaces from the java.util package but
does not include sub-packages.
public Geeks() {
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
// java.util.Vector is imported, hence we are
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
// able to access it directly in our code.
Vector v = new Vector();
// java.util.ArrayList is not imported, hence
// we are referring to it using the complete
// package name.
java.util.ArrayList l = new java.util.ArrayList();
}
Note:
import java.util.Date;
import my.package.Date;
1. Built-in Packages
2. User-defined Packages
o.getNames(s);
We use cookies
} to ensure you have the best browsing experience on our website. By using our site, you
}
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Note: MyClass.java must be saved inside the myPackage directory since
it is a part of the package.
Example:
class Geeks {
public static void main(String args[]) {
Output
GeeksforGeeks
import java.util.*;
import java.sql.*;
//And then use Date class, then we will get a compile-time error :
We use cookies
Date to ensure
today you have the java.util.Date
; //ERROR– best browsing experience on our website. By using our site, you
or java.sql.Date?
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
The compiler will not be able to figure out which Date class do we
want. This problem can be solved by using a specific import statement:
import java.util.Date;
import java.sql.*;
If we need both Date classes then, we need to use a full package name
every time we declare a new object of that class. For Example:
$BASE_DIR/com/zzz/project1/subproject2/Circle.class
Setting CLASSPATH
CLASSPATH can be set by any of the following ways:
.c:\javaproject\classes;d:\tomcat\lib\servlet-api.jar
package package_name;
package package_one;
import package_name.ClassOne;
import package_one.ClassTwo;
Now
We having
use cookies a look
to ensure youat the
have thedirectory
best browsingstructure ofour
experience on both theBypackages
website. using our site,and
you
acknowledge
the testing classthat you have read and understood our Cookie Policy & Privacy Policy
file:
Access Modifiers in the Context of Packages
Important points:
Similar Reads
Java | Java Packages | Question 3
Predict the output of following Java program // Note static keyword after
import. import static java.lang.System.*; class StaticImportDemo { public…
1 min read
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
How acknowledge
to Create thatDifferent
you have Packages For Different
read and understood Classes
our Cookie Policy in Java?
& Privacy Policy