Your SlideShare is downloading. ×
0
09   packages
09   packages
09   packages
09   packages
09   packages
09   packages
09   packages
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

09 packages

136

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
136
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
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
    DhrubojyotiKayal
  • 2. Packages
    Import
    Agenda
  • 3. Contains a group of classes, organized together under a single namespace.
    Ex – java.util, java.sql
    Essentially folder to store source and compiled classes – library / compilation unit
    How can you use Classes in other packages?
    Using fully qualified class name
    public class FullQualification {
    public static void main(String[] args) {
    java.util.ArrayListlist = new java.util.ArrayList();
    }
    }
    Package
  • 4. Use import keyword to use one class in a different package
    import java.util.ArrayList;
    public class SingleImport {
    public static void main(String[] args) {
    ArrayListlist = new java.util.ArrayList();
    }
    }
    If you want all the classes in java.util then
    Import java.util.*;
    Import
  • 5. Use a package statement, it must appear as the first non-comment in the file.
    package com.training.java
    You creating a new compilation unit or library
    In order to use the classes in this package you either use fully qualified class name or import statements
    Custom package
  • 6. package com.training.java;
    public class MyClass {
    // ...
    }
    public class QualifiedMyClass {
    public static void main(String[] args) {
    com.training.java.MyClassm =
    new com.training.java.MyClass();
    }
    }
    import com.training.java.MyClass;
    public class ImportedMyClass {
    public static void main(String[] args) {
    MyClassm = new MyClass();
    }
    }
    Import in Action
  • 7. Q&A

×