aspose file tools
The moose likes Beginning Java and the fly likes import servlet packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import servlet packages" Watch "import servlet packages" New topic

import servlet packages

Kallol Das

Joined: Apr 24, 2007
Posts: 4
import javax.servlet.*;
import javax.servlet.http.*;

My question is:

javax.servlet is the parent package which contains javax.servlet.http package,then 1st line is sufficient to import both the packages,Right? then why there is a requirement to separately import javax.servlet.http package?(in the books like Complete reference there is mention of both these import statements to import javax.servlet.http package)
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42955
Welcome to JavaRanch.

then 1st line is sufficient to import both the packages,Right?

No. Importing a package does not recursively import any child packages, so both import statements are necessary.
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
Imports can be of 2 types:

1. Specifying the whole Class like "import java.util.ArrayList;"

2. Specifying the Package name like "java.util.*;"

For more details refer:
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Srikanth Ramu:
Imports can be of 2 types...
For more details refer:

That link is to the old second edition of the JLS. The third edition introduced static imports, so there are now four types of import statements...
  • 7.5.1 Single-Type-Import Declaration
  • 7.5.2 Type-Import-on-Demand Declaration
  • 7.5.3 Single Static Import Declaration
  • 7.5.4 Static-Import-on-Demand Declaration
  • Addressing the original question, JLS - 7.5 Import Declarations states, "A type-import-on-demand declaration (�7.5.2) imports all the accessible (�6.6) types of a named type or package as needed." Packages are not types.
    [ April 24, 2007: Message edited by: marc weber ]

    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    Kallol Das

    Joined: Apr 24, 2007
    Posts: 4
    Thnx guys for your informative inputs.
    I have joined this ranch today.I am humbled by the kind of(prompt and quality) response I got.thank you very much.

    I agree. Here's the link:
    subject: import servlet packages