Packages<br />DhrubojyotiKayal<br />
Packages<br />Import<br />Agenda<br />
Contains a group of classes, organized together under a single namespace. <br />Ex – java.util, java.sql<br />Essentially ...
Use import keyword to use one class in a different package<br />import java.util.ArrayList; <br />public class SingleImpor...
Use a package statement, it must appear as the first non-comment in the file.<br />package com.training.java<br />You crea...
package com.training.java; <br />public class MyClass { <br />	// ... <br />} <br />public class QualifiedMyClass { <br />...
Q&A<br />
Upcoming SlideShare
Loading in...5
×

09 packages

148

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
148
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

09 packages

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

    Clipping is a handy way to collect important slides you want to go back to later.

×