Skip to main content

Java Package Interview Questions


Java Package




1. What is the purpose of package in Java?

A package is used to encapsulate a group of classes, interfaces and sub-packages. Often, it is a hierarchical structure of storing information. It is easier to organize the related classes and subpackages in this manner. A Package also provides access protection for classes andinterfaces. A package also helps in removing naming collision.

2. What is java.lang package?

In Java, java.lang package contains the classes that are fundamental to the design of Java programming language. The most important class in this package is Object class. It also contains wrapper classes like- Integer, Boolean, Character etc. It provides Math class for mathematical operations.

3. Which is the most important class in Java?

It is an open-ended question with many answers. In my view, Object class is the most important class of Java programming language. It is the root of all the classes in Java. It provides some very important and fundamental methods.

4.Is it mandatory to import java.lang package every time?

No. By default, JVM loads it internally.

5. Can you import same package or class twice in your class?

If we import same package multiple times in a class, compiler includes it only once. So neither JVM nor Compiler gives any error/warning on including a package multiple times. If you have two classes with same name, then you may get name collision on importing the class erroneously. JVM internally loads the class only one time.

6. What is a static import in Java?

Static import is similar to normal import declaration. Normal import allows us to import classes from packages without using package qualifier. Static import allows us to import static members from a class without using class qualifier.

7.What is the difference between import static com.test.Fooclass and import com.test.Fooclass?

First import is a static import and the second import is normal import of a class. First import allows us to import static members of class.








Comments

Popular posts from this blog

DOCKER Interview questions

DOCKER 1. What is Docker? Docker is Open Source software. It provides the automation of Linux application deployment in a software container. We can do operating system level virtualization on Linux with Docker. Docker can package software in a complete file system that contains software code, runtime environment, system tools, & libraries that are required to install and run the software on a server. 2. What is the difference between Docker image and Docker container? Docker container is simply an instance of Docker image. A Docker image is an immutable file, which is a snapshot of container. We create an image with build command. When we use run command, an Image will produce a container. In programming language, an Image is a Class and a Container is an instance of the class. 3. How will you remove an image from Docker? We can use docker rmi command to delete an image from our local system. Exact command is: % docker rmi <Image Id> If we want to fin...

Inheritance Interview Questions in Java

Most Frequently asked Interview Questions and Answer in Java:            In this Java Interview Question blog, we have covered almost total 100+ important Inheritance in OOPs concepts  interview questions and answer in java for freshers and experienced candidates one by one topics. Inheritance Interview Questions in Java Method Overloading and Overriding Interview Questions Polymorphism Interview Questions in Java Abstraction Interview Questions in Java             This post on JAVA Interview Questions and Answers is prepared to help you understand the basic concepts of Java programming for top composes interview purposes. All the most important JAVA concepts are explained here with examples for your easy understanding.              This blog covers core JAVA topics, advance java topics and also industry level project related most important Interview Ques...

git interview questions

GIT 1.What is the purpose of git stash drop? In case we do not need a specific stash, we use git stash drop command to remove it from the list of stashes. By default, this command removes to latest added stash To remove a specific stash we specify as argument in the git stash drop <stashname> command. 2. What is the HEAD in GIT? A HEAD is a reference to the currently checked out commit. It is a symbolic reference to the branch that we have checked out. At any given time, one head is selected as the ‘current head’ This head is also known as HEAD (always in uppercase). 3. What is the most popular branching strategy in GIT? There are many ways to do branching in GIT. One of the popular ways is to maintain two branches: master : This branch is used for production. In this branch HEAD is always in production ready state. develop : This branch is used for development. In this branch we store the latest code developed in project. This is work in progress code. On...