This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about import statements" Watch "Question about import statements" New topic
Author

Question about import statements

Steve Jogan
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14952
    
  26

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
 
It's not a secret anymore!