This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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: 63534

Moved to Java in General (beginner)

[Asking smart questions] [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
jQuery in Action, 3rd edition