Your SlideShare is downloading. ×
  • Like
14   packages
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

14 packages

  • 242 views
Published

Hariprasanna V (9843824677)

Hariprasanna V (9843824677)

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
242
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
4
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Packages Tonga Institute of Higher Education
  • 2. Pre-Built Objects and Methods
      • Java has many pre-built objects for us to use.
      • Doorknob analogy
        • We want to add a doorknob to a door.
        • We could make our own.
        • But it’s easier to use a pre-built doorknob.
        • We still need to do work to add the doorknob to our door.
      • You can find a list of pre-built objects in the Java Developer’s Kit documentation.
    System.out.println("We Miss Dave!"); Method Name Parameter Package
  • 3. Demonstration Java API Documentation
  • 4. Organizing Classes
    • Java comes with over 2,700 different classes for doing different things.
    • Sun needed a way to organize the classes into groups, they decided to use packages.
    • A package is a group of related classes.
  • 5. Packages
    • Java contains 140 different packages.
    • These packages are arranged hierarchically (packages inside of packages).
    java awt event geom image lang ref reflect acl security spec
  • 6. Package Names
    • The name of the package is actually a list of names, separated by periods.
    java.awt.image; java awt event geom image lang ref reflect acl security spec
  • 7. Using Packages
    • If you want to use a built-in Java class, first look it up in the Java Application Interface. (API)
    • You can find the Java API documentation on the course website page.
      • http://www.tihe.org/courses/it151
    This is the API entry for the Graphics class. The package for this class is java.awt .
  • 8. Using Packages (cont.)
    • Once you know the package for a class, import it into your program.
    • To import all classes in a package, use the wild card (*).
    import java.awt.Graphics; import java.awt.*;
  • 9. Case Study: Problem
    • Michael wants to use the Socket class in his program for Networking.
    • Which package does he need to include in his program?
    • What is the line of code he needs to write?
  • 10. Case Study: Answer
    • Look up the Socket class in the Java API
    • Use the import command to include the package:
    • or
    import java.net.Socket; import java.net.*;
  • 11. Defining a Package
    • If you want to make your own package to be used in other programs, define it.
    • Defining packages can lead to problems compiling your program.
    • If you have multiple files in your project, make sure they are all defined in the same package.
    package myprojects.helloworld;