File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Author

import servlet packages

Kallol Das
Greenhorn

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
Marshal

Joined: Mar 22, 2005
Posts: 41865
    
  63
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.


Ping & DNS - my free Android networking tools app
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:
http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#70209
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Srikanth Ramu:
Imports can be of 2 types...
For more details refer:
http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#70209

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
    sscce.org
    Kallol Das
    Greenhorn

    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.





    Kallol
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: import servlet packages