File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes regarding packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regarding packages" Watch "regarding packages" New topic

regarding packages

A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi all,

see the lines below.

here my question is javax.servlet.http.* is a subpackage of servlet package ,that mean what ever the classes in http package those are already available in servlet what is the reason behind writing these two statements in servlet program.please give solution to me.


amod gole
Ranch Hand

Joined: Dec 07, 2005
Posts: 83
hi babu,

if you read carefully,Package concept then you will get an idea that
when you import any package then only classe(public)and interface of that package are get imported and not sub package
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62826

Moved to Java in General (beginner)

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306

what is the reason behind writing these two statements in servlet program.please give solution to me.

import javax.servlet.*;
import javax.servlet.http.*;

As Amod mentioned above "sub packages" are not imported with import statement. That means to import a Class in the package javax.servlet.http, you need to specify the full package name. A partial package name is not enough.

Javax.servlet is a full package name when you consider classes and interfaces in javax.servlet package. For example javax.Servlet can import all interfaces and classes listed in the api
Note that Classes and interfaces under java.servlet.http cannot be imported by importing javax.servlet.*
Classes and interfaces listed under javax.servlet.http is listed in the api
I agree. Here's the link:
subject: regarding packages