how to import package in java code example

Example 1: how to import whole package in java

import package.* //imports entire package

Example 2: java import

import java.util.* 			//imports entire utility package
import java.util.scanner 	// imports just the scanner object
  
public class CheeseBurgerOrderer {
  public static void main(String[] args) {
    // code body
  }
}

Example 3: java file package import

import java.io.File;

Example 4: java packages example

// import <package>			-> Imports the whole package
// import <package>.<class> -> Imports a certain class
import java.util.Scanner;

Example 5: how to import package in java

import package.name.Class;   // Import a single class
import package.name.*;   // Import the whole package

Tags:

Java Example