Importing All Classes in a Package

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes.

Importing All Classes in a Package

Often a program will need more than one class from a particular package like java.util. It is convenient in this case to import all the classes in the package at once, as the following program does:

import java.util.*;

class ImportDemo04
{
  public static void main ( String[] args )
  {
    Scanner scan ;    // a class in java.util
    Random rand ;     // another class in java.util
    
    scan = new Scanner( System.in );
    rand = new Random( );
    
    // do something with the Scanner and Random objects (see following chapters)
  }
}

The part import java.util.* means to import all the classes in the package. It does not hurt to do this, even if you only need one or two of them.

QUESTION 17:

Is there ever (do you suppose) a need to make an object out of a single integer?