wood burning stoves
The moose likes Beginning Java and the fly likes Question about import statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about import statements" Watch "Question about import statements" New topic

Question about import statements

Steve Jogan

Joined: Feb 28, 2010
Posts: 3
I have noticed that many sample codes have more than one import.

As an example.

import javax.swing.*;
import java.awt.event*;
import java.awt.*;
import java.awt.geom*;
import java.util.*;

Should not the "import java.awt.*" contain the ".geom" and ".event" import as well?

Is there something about the import command I am missing?

thank you.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Steve Jogan wrote:Should not the "import java.awt.*" contain the ".geom" and ".event" import as well?

No. The * encompasses only the classes within the package. It does not recursively include sub-packages.

[Asking smart questions] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15043

Welcome to JavaRanch.

Not only does the import statement not automatically include subpackages, Java doesn't have a concept of subpackages in general - so also with regard to other aspects, packages that start with the same name should just be regarded as completely separate packages without a super-sub relationship between them.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link: http://aspose.com/file-tools
subject: Question about import statements
jQuery in Action, 3rd edition