Table of Contents

Java Importing a Package

To import the java package into a class, we need to use the java import keyword which is used to access the package and its classes into the java program.

Use import to access built-in and user-defined packages into your java source file to refer to a class in another package by directly using its name.


import;   // To import a certain class only
import*   // To import the whole package


import java.util.Date; // imports only Date class
import*;      // imports everything inside package

Example for creating and importing java packages:

//save by  
package greeting;  // creating package
public class Greet{  
   public void msg() {

//save by  
package Java;  
import greeting.*;    //importing package
class Main {  
   public static void main(String args[]) {  
       Greet g = new Greet();  

Hello  */

Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?