Showing posts with label Java Packages. Show all posts
Showing posts with label Java Packages. Show all posts

Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.BOB compile?


Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying, cannot resolve symbol.



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

What is a Java package and how is it used?


Or

Explain the usage of Java packages.

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.
For example: The Java API is grouped into libraries of related classes and interfaces; these libraries are known as package.



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

Does importing a package imports the sub packages as well? E.g. Does importing com.bob.* also import com.bob.code.*?


No you will have to import the sub packages explicitly. Importing com.bob.* will import classes in the package bob only. It will not import any class in any of its sub package’s.



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

Can I import same package/class twice? Will the JVM load the package twice at runtime?


One can import the same package or same class multiple times. Neither compiler nor JVM complains anything about it. And the JVM will internally load the class only once no matter how many times you import the same class.



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

Which package is always imported by default?


No. It is by default loaded internally by the JVM. The java.lang package is always imported by default.



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

Java Packages


Java Interview Questions site discussing core java IT technical interview questions in detail. These are some of the java job interview questions me and my friends have faced regularly in campus interviews and off campuses . I have consolidated all of them from different people and communities into a vast resource of core java interview questions all in one place. So I am giving you a chance to prepare well by going through each of the java interview faqs organized by java topics, before attending a technical interview on java.


Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

Related JAVA Questions Posts