Java Interview Questions - package

1. What is package?

Package is a collection of group of similar types of classes, interfaces and sub packages.

2. State the use of package?

  1. Package use to search .class file very faster.
  2. It is use to categorize classes & interfaces so that they can be easily maintained.
  3. Package use to remove naming collision.

3. What are the diff. types of package with example& define them?

Package categorized into 2 types:

  1. Built-in package
  2. User-defined package.

Built-in package-If the package already design & stored in the predefined class then it is known as Built –in package User-defined package-User-defined classes are the collection of user defined classes.

4. How to create a user defined package?

Package is a keyword in java which is used to designed user defined package.

5. What is the name of default package & its benefits?

Lang is the default package in java.

6. How to set the class path & its advantage?

Class path able to set by 2 different ways:

  1. Permanently within environment variables
  2. Temporarily by set class path command.

7. How to compile a package program?

Javac -d . filename.java

8. How to create a .jar file?

jar -cvf Filename.jar Filename.class

9. How to create a jar executable file?

jar -cmf manifest_fileFilename.jar Filename.class

10. How to use the class file, i.e. ways to access the class file. And diff b/w import and fully qualified name?

Two different ways user can use the class file.

  1. by import keyword
  2. by fully qualified name.

In case of package importing no need to specify the full path of package. But in case of fully qualified name user has to specify the package name each time to access the class and it is not flexible.

11. Specify a situation where fully qualified is necessary?

Fully qualified name is requiredwhen same class present in more than one package.

12. Is there any need to import java.lang package?

No not required

13. How to access package from another package?

There are 3 ways to access the package from another package

  1. import package.*;
  2. import package . class name.
  3. fully qualified name.

14. What is sub package?

Package inside the package is called the sub package.It is use to categorise the package further.

15. Which package is always imported by default?

Lang package.

16. Does Importing a package imports its sub-packages as well in Java?

No importing package means only current package not its sub-package.

17. What are the advantages of package?

  1. package provides access protection.
  2. package removes naming collision.

18. State the use of import keyword?

The import keyword used to make the classes and interfaces of another package accessible to the current package.

19. How much pre-defined package java supports?

80,000 classes present in 202 no of packages.

20. Who is the default package in java?

Lang is the default package in java.

21. State the use of package keywords

The package keyword is used to create a package.

22. When to use fully qualified name ?

We need to use fully qualified name every time when accessing the classes and interfaces.

23. State the operation & package of Socket& Server Socket classes?

Socket & Server socket class present in net package and its operation mainly for networking purpose.

24. Input/Output classes present in which package?

Input/Output classes present in io package.

25. What are the ways to load class file?

There are 2 ways to load class file

Temporary:

  1. by setting the class path in the command prompt.
  2. by class path switch.

Permanent:

  1. by setting the class path in the environment variable.
  2. by creating the jar file.

26. How to create document API in java?

Document API can create in java by the help of javadoc tool.

27. Which package is used for achieving the language Functionalities?

java.lang.* is used for language functionalities.

28. Which package is used for developing file handling application?

java.io.* is used for file handling application.

29. Which package is used for developing GUI components?

java.awt.* is used for GUI components.

30. Which package is used for developing browser oriented application?

java.applet.* is used for browser oriented application.

31. Which package is used for developing client server application?

java.net.* is used for client server application.

32. Which package is used for developing quality or reliable application in java?

java.util.* is used for quality or reliable application in java.

33. Which package is used for formatting data and time on day to day business operation?

java.text.* is used for formatting data and time on day to day business operation.

34. State the use of Event package?

This package is used for providing the functionality of GUI components.

35. Which package is also known as collection framework in java?

java.util.* is also known as collection framework in java.

36. Which package is used for runtime information about the class and interface?

java.lang.reflect.* is used for study run time information about the class and interface.

37. Which package is used for retrieving data from database & performing various operation on database?

java.sql.* is used for retrieving data from db& performing various operation on db.

38. Which is known as universal access specifier?

Public access specifier.

39. Which is known as package access specifier?

Default access specifier.

40. Which is known as inherited access specifier?

Protected access specifier.

41. Which is known as native access specifier?

Private access specifier.

42. What access specifier represent?

Access specifier represent the visibility of data or accessibility of data.