Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding packages

 
A Babu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 package.so what is the reason behind writing these two statements in servlet program.please give solution to me.

cheers,
babu.
 
amod gole
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java in General (beginner)
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic