💻Step 12: Packages – 7th hour + code

Learn with youtube video-


– Group of similar types of classes, interfaces and subpackages.


Comparing built-in and user-defined packages in Java:

FeatureBuilt-in PackagesUser-defined Packages
Provided byJava runtime environmentDeveloper
ContainsPre-defined classes, interfaces, and methodsClasses and interfaces defined by developer
ImportingAutomatically importedMust be explicitly imported using import keyword
Naming conventionFollows specific convention (e.g. java.util, java.io)Can be named by developer, as long as it is a valid Java identifier
PurposeProvide pre-defined functionalityOrganize and reuse developer’s own code

💡1- Built in packages

– also called as predefined packages in java
 i.e- java.lang, java.util, java.io etc

💡2- User defined packages

-also called as developer/user defined packages

[To use class of other package, we have 3 options to choose]

Fully Qualified Namepackage.ClassName.methodName()java.util.ArrayList.add()
Import using Package.Class before Class Declarationimport Package.Class;import java.util.ArrayList;
Import Full Packageimport Package.*;import java.util.*;
Static Importimport static Package.Class.methodName;import static java.lang.Math.PI;

💡a- using fully qualified name
💡b- by importing package.class (recommended)

💡C- by importing full package*

Note– importing package doesn’t include subpackage

💡Static Import

used to import only static member of a class instead of class.


Interview Questions —

  • How packages are related to access modifiers?
  • How many ways are available to import class of other packages?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.