• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import servlet packages

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
     
    Kallol Das
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic