0% found this document useful (0 votes)
4 views8 pages

Java Packages ObjectClass

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Java Packages ObjectClass

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Java Packages

Organizing Classes and Interfaces


Introduction to Packages

• Packages are folders or directories.


• Used to store Java programs (Classes & Interfaces).
• Achieve modularity in programs.
• Provide flexibility & easy maintenance.
Types of Packages

• 1. Built-in Packages (Predefined in Java)


• 2. User-defined Packages (Created by programmers)
Built-in Packages

• java.lang – Fundamental classes


• java.io – Input/Output classes
• java.util – Utility classes (Collections, Date, etc.)
• java.sql – Database connectivity
• java.net – Networking classes
Creating User-defined Packages

• 1. Write classes and save them inside a directory.


• 2. Use 'package' keyword at the top of the program.
• 3. Compile using: javac -d . ClassName.java
• 4. Import in another program using: import packagename.ClassName;
Object Class in Java

• The Object class is the parent of all Java classes.


• Every class in Java directly or indirectly inherits Object.
• Defined in java.lang package.
Important Methods of Object Class

• toString() – Returns string representation of the object.


• equals() – Compares two objects.
• hashCode() – Returns hash code value.
• clone() – Creates and returns a copy of the object.
• finalize() – Called before garbage collection.
• getClass() – Returns runtime class of the object.
Class Hierarchy

• At the top: Object Class


• Every other class extends Object directly or indirectly
• Example: String, Number, Exception, etc.

You might also like