Java Classes - Lecure#9
Java Classes - Lecure#9
(OOP)
Classes
Packages in java
►A package as the name suggests is a
pack(group) of classes, interfaces and other
packages
► types of packages
▪ built-in packages
►Import java.util.Scanner
►→ java is a top level package
→ util is a sub package
→ and Scanner is a class which is present in the
sub package util.
▪ user defined package
Advantages of using a package in Java
► Reusability: While developing a project in java, we often feel
that there are few things that we are writing again and again
in our code. Using packages, you can create such things in
form of classes inside a package and whenever you need to
perform that same task, just import that package and use the
class.
► Better Organization: Again, in large java projects where we
have several hundreds of classes, it is always required to group
the similar types of classes in a meaningful package name so
that you can organize your project better and when you need
something you can quickly locate it and use it, which improves
the efficiency.
► Name Conflicts: We can define two classes with the same
name in different packages so to avoid name collision, we can
use packages