2. What are ‘Packages’
in JAVA?A Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations )
providing access protection and namespace management.
It can be further categorized in two
types:
3. • We were storing all the coded files inside the same directory, what if, someday we need to
make a project?
• As the applications grows it becomes difficult to keep all the files in same directory, also we need to
ensure that the name we choose should be unique. To address this problem java introduces a mechanism
to manage all the classes this is called Packages
What does it mean
actually?
• Let’s see…
Directory Structure showing the inbuilt
packages
4. • Now, the inbuilt packages will be available to user with all use cases, but what if we need to do
something which is not pre-defined?
• We’ll be creating our own packages.
• Lets see how!
By default I wrote all files here inside this directory.
Now if I’ve to create a package.
Firstly, creating a new directory
Creating new files inside the
directory
Now, the package
name should be the
same as directory
name
5. • Now, if we want to access the
package
Test.*;
Represents all files
inside the Test directory
On running this, we get
Inside Test, class sample
is present.
By this we can observe that the package is properly imported.
6. What are ‘Interfaces’ in
JAVA?• An interface in java is a blueprint of a class.
• It has static constants and abstract methods.
• The interface in java is a mechanism to achieve abstraction.
Just like a class can inherit or extend from another class, similarly the interface can inherit or extend from another interface
7. How do we declare an
interface?• Let’s see the syntax for writing an interface…
• An interface is implicitly abstract.
• So not need to use the abstract keyword while declaring an interface.
• Each Fields in an interface is also implicitly static and final, so the static and final keyword is
not needed (Refer below diagram).
• Methods in an interface are also implicitly public.
8. Creating an interface
Implementing the interface
Completing the body of
the abstract method
After running the program
Interface helps us getting an implementation of
multi-parent inheritance which is not there in JAVA
10. Thank You
“I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge.
Knowledge is limited.
Imagination encircles the world.”
― AlbertEinstein
Now, thought for the day,