1 - Does this mean: I could find a folder structure like javax/servlet/http
somewhere and inside that HttpServlet.class file would be present?
In this case, probably not in the file system, per se. (This class is part of the J2SE runtime libraries.)
2 - If not, where exactly this class file could be found?
In a JAR file that is on your JVM's classpath or bootclasspath. The JAR file is an archive containing .class
files and other resources. The pathname of the class within the JAR file would be /javax/servlet/http/HttpServlet.class
. (In this case the class in the rt.jar
file.)
3 - Does this mean: These are just nested namespaces with no relevance to folder structures?
No. If you have file system folders on your classpath, they may be searched to find classes, before or after JAR files, depending on where on the classpath they are. The classpath effectively overlays the namespaces. Namespaces of JAR files can overlay namespaces of file system folders, and vice versa, depending on the effective classpath.
4 - Package name in the above mentioned import would be javax.servlet or javax.servlet.http?
javax.servlet.http
4 continued - Probably both are packages and first one is super package of the later one?
Both are packages, but there is no such thing as a "super package" in Java. As far as the Java language is concerned javax.servlet
and javax.servlet.http
are unrelated packages. Some people might say that javax.servlet
is the parent package of javax.servlet.http
, but this statement has no intrinsic meaning from the perspective of the Java language. The apparent parent-child relationship is purely conventional.
5 - How is this class file actually included? I've read import is not like C/C++ include.
The class file is not "included" in any sense. A Java import
is little more than a shorthand that allows you to refer to the imported name without qualifying it with its full package name.