SlideShare a Scribd company logo
© Prognoz Technologies Pvt. Ltd
Topic Covered:
 Understand the use of casting objects
 Understand Packages & Access Specifier
 Create static variables, methods, and initializers
 Modifiers
 Create and use an interface
 Inner class & Anonymous class
Objectives
© Prognoz Technologies Pvt. Ltd
2
Packages
 Provide a mechanism for grouping a variety of classes and / or interfaces together.
 Grouping is based on functionality.
Benefits:
 The classes contained in the packages of other programs can be reused.
 In packages, classes can be unique compared with classes in other packages.
 Packages provides a way to hide classes.
© Prognoz Technologies Pvt. Ltd
3
Packages
 Two types of packages: 1. Java API packages 2. User defined packages
Java API Packages:
 A large number of classes grouped into different packages based on
functionality. Examples:
1. java.lang
2. java.util
3. java.io
4. java.awt
5.java.net
6.java. applet etc.
© Prognoz Technologies Pvt. Ltd
4
Package
Color
Graphics
Image
Java
awt
Package containing awt package
Package containing classes
© Prognoz Technologies Pvt. Ltd
5
Accessing Classes in a Package
1. Fully Qualified class name:
Example:java.awt.Color
2. import packagename.classname;
Example: import java.awt.Color;
or
import packagename.*;
Example: import java.awt.*;
 Import statement must appear at the top of the file, before any class
declaration.
6
Creating Your Own Package
1. Declare the package at the
beginning of a file using the
form
package packagename;
2. Define the class that is to be put
in the package and declare it
public.
3. Create a subdirectory under the
directory where the main source
files are stored.
4. Store the listing as
classname.java in the
subdirectory created.
5. Compile the file. This creates
.class file in the subdirectory.
Example:
package firstPackage;
Public class FirstClass
{
//Body of the class
}
7
Example1-Package
package p1;
public class ClassA
{
public void displayA( )
{
System.out.println(“Class A”);
}
}
import p1.*;
Class testclass
{
public static void main(String str[])
{
ClassA obA=new ClassA();
obA.displayA();
}
}Source file – ClassA.java
Subdirectory-p1
ClassA.Java and ClassA.class->p1
Source file-testclass.java
testclass.java and
testclass.class->in a directory of
which p1 is subdirectory.
© Prognoz Technologies Pvt. Ltd
8
Creating Packages
 Consider the following declaration:
package firstPackage.secondPackage;
This package is stored in subdirectory named firstPackage.secondPackage.
 A java package can contain more than one class definitions that can be declared
as public.
 Only one of the classes may be declared public and that class name with .java
extension is the source file name.
9
Example2-Package
package p2;
public class ClassB
{
protected int m =10;
public void displayB()
{
System.out.println(“Class B”);
System.out.println(“m= “+m);
}
}
import p1.*;
import p2.*;
class PackageTest2
{
public static void main(String str[])
{
ClassA obA=new ClassA();
Classb obB=new ClassB();
obA.displayA();
obB.displayB();
}
}
10
Example 3- Package
import p2.ClassB;
class ClassC extends ClassB
{
int n=20;
void displayC()
{
System.out.println(“Class C”);
System.out.println(“m= “+m);
System.out.println(“n= “+n);
}
}
class PackageTest3
{
public static void main(String args[])
{
ClassC obC = new ClassC();
obC.displayB();
obC.displayC();
}
}
11
Package
package p1;
public class Teacher
{………….}
public class Student
{……………..}
package p2;
public class Courses
{………..}
public class Student
{………………..}
import p1.*;
import p2.*;
Student student1; //Error
Correct Code:
import p1.*;
import p2.*;
p1.Student student1;
p2.Student student2;
© Prognoz Technologies Pvt. Ltd
12
Default Package
 If a source file does not begin with the package statement, the classes contained
in the source file reside in the default package
 The java compiler automatically looks in the default package to find classes.
© Prognoz Technologies Pvt. Ltd
13
Finding Packages
 Two ways:
1.By default, java runtime system uses current directory as starting point and
searches all the subdirectories for the package.
2.Specify a directory path using CLASSPATH environmental variable.
© Prognoz Technologies Pvt. Ltd
14
CLASSPATH Environment
Variable
 The compiler and runtime interpreter know how to find standard packages such
as java.lang and java.util
 The CLASSPATH environment variable is used to direct the compiler and
interpreter to where programmer defined imported packages can be found
 The CLASSPATH environment variable is an ordered list of directories and files
© Prognoz Technologies Pvt. Ltd
15
CLASSPATH Environment
Variable
 To set the CLASSPATH variable we use the following command:
set CLASSPATH=c:
 Java compiler and interpreter searches the user defined packages from the above
directory.
 To clear the previous setting we use:
set CLASSPATH=
Example1-Package[Using CLASSPATH]
package p1;
public class ClassA
{
public void displayA( )
{
System.out.println(“Class A”);
}
}
import p1.ClassA;
Class PackageTest1
{
public static void main(String str[])
{
ClassA obA=new ClassA();
obA.displayA();
}
}
Source file – c:p1ClassA.java
Compile-javac c:p1ClassA.java
Class file in –c:p1ClassA.class
Source file-
c:javajdk1.6.0_06binPackageTest1.java
Compile-javac PackageTest1.java
Copy –PackageTest1.class -> c:
Execute-java PackageTest1
17
Example2-Package[Using
CLASSPATH]
package p2;
public class ClassB
{
protected int m =10;
public void displayB()
{
System.out.println(“Class B”);
System.out.println(“m= “+m);
}
}
import p1.*;
import p2.*;
class PackageTest2
{
public static void main(String str[])
{
ClassA obA=new ClassA();
Classb obB=new ClassB();
obA.displayA();
obB.displayB();
}
}
Source file – c:p2ClassB.java
Compile-c:p2ClassB.java
Class file in –:p2ClassB.class
c:javajdk1.6.0_06binPackageTest2.java
Compile-javac PackageTest2.java
Copy –PackageTest2.class -> c:
Execute-java PackageTest2
18
Example 3- Package[Using CLASSPATH]
import p2.ClassB;
class ClassC extends ClassB
{
int n=20;
void displayC()
{
System.out.println(“Class C”);
System.out.println(“m= “+m);
System.out.println(“n= “+n);
}
}
class PackageTest3
{
public static void main(String args[])
{
ClassC obC = new ClassC();
obC.displayB();
obC.displayC();
}
}
Source file – c:ClassC.java
Compile-c:ClassC.java
Class file in –c:ClassC.class
Source file-c:javajdk1.6.0_06binPackageTest3.java
Compile-javac PackageTest3.java
Copy –PackageTest3.class -> c:
Execute-java PackageTest3
© Prognoz Technologies Pvt. Ltd
19
Adding a Class to a Package
 Every java source file can contain only class declared as
public.
 The name of the source file should be same as the name of
the public class with .java extension.
package p1;
public ClassA{ ……………}
Source file : ClassA.java
Subdirectory: p1
package p1;
public ClassB{…………}
Source file: ClassB.java
Subdirectory:p1
© Prognoz Technologies Pvt. Ltd
20
Adding a Class to a Package
 Decide the name of the package.
 Create the subdirectory with this name under the directory where the main source
file is located.
 Create classes to be placed in the package in separate source files and declare the
package statement
package packagename;
 Compile each source file. When completed the package will contain .class files of
the source files.
© Prognoz Technologies Pvt. Ltd
Summary!!

More Related Content

What's hot

Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
TharuniDiddekunta
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Java packages
Java packagesJava packages
Java packages
Raja Sekhar
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
Vishnu Suresh
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
İbrahim Kürce
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
tanu_jaswal
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 

What's hot (20)

Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Method overriding
Method overridingMethod overriding
Method overriding
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Java packages
Java packagesJava packages
Java packages
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 

Viewers also liked

Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
Lucas Jellema
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packagesDeepak Sharma
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
dheeraj_cse
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Dynamic Routing All Algorithms, Working And Basics
Dynamic Routing All Algorithms, Working And BasicsDynamic Routing All Algorithms, Working And Basics
Dynamic Routing All Algorithms, Working And Basics
Harsh Mehta
 
Getting started with performance testing
Getting started with performance testingGetting started with performance testing
Getting started with performance testing
Testplant
 
Presence Agent y Presence Scripting para personas con limitaciones visuales
Presence Agent y Presence Scripting para personas con limitaciones visualesPresence Agent y Presence Scripting para personas con limitaciones visuales
Presence Agent y Presence Scripting para personas con limitaciones visuales
Presence Technology
 
Innovation In The Workplace Andrew James
Innovation In The Workplace   Andrew JamesInnovation In The Workplace   Andrew James
Innovation In The Workplace Andrew James
Konica Minolta
 
New Research: Cloud, Cost & Complexity Impact IAM & IT
New Research: Cloud, Cost & Complexity Impact IAM & ITNew Research: Cloud, Cost & Complexity Impact IAM & IT
New Research: Cloud, Cost & Complexity Impact IAM & ITSymplified
 
Dr Ravi Gupta
Dr Ravi GuptaDr Ravi Gupta
Top 10 Business Continuity Disasters
Top 10 Business Continuity DisastersTop 10 Business Continuity Disasters
Top 10 Business Continuity Disasters
Rentsys Recovery Services
 
Rsa2012 下一代安全的战略思考-绿盟科技赵粮
Rsa2012 下一代安全的战略思考-绿盟科技赵粮Rsa2012 下一代安全的战略思考-绿盟科技赵粮
Rsa2012 下一代安全的战略思考-绿盟科技赵粮
NSFOCUS
 
TXT Next Presentation
TXT Next Presentation TXT Next Presentation
TXT Next Presentation
TXT e-solutions
 
Perceptive Software Scope
Perceptive Software ScopePerceptive Software Scope
Perceptive Software Scope
Perceptive Software Pty Ltd
 
Running SagePFW in a Private Cloud
Running SagePFW in a Private CloudRunning SagePFW in a Private Cloud
Running SagePFW in a Private CloudVertical Solutions
 
Pramata Tech Dinosaurs ePaper - Social Sharing
Pramata Tech Dinosaurs ePaper - Social SharingPramata Tech Dinosaurs ePaper - Social Sharing
Pramata Tech Dinosaurs ePaper - Social SharingTidemark Systems Inc.
 
5 Reasons to Recycle in the D.C. Metro Area
5 Reasons to Recycle in the D.C. Metro Area5 Reasons to Recycle in the D.C. Metro Area
5 Reasons to Recycle in the D.C. Metro Area
Sims Recycling Solutions
 

Viewers also liked (17)

Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packages
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Java package
Java packageJava package
Java package
 
Dynamic Routing All Algorithms, Working And Basics
Dynamic Routing All Algorithms, Working And BasicsDynamic Routing All Algorithms, Working And Basics
Dynamic Routing All Algorithms, Working And Basics
 
Getting started with performance testing
Getting started with performance testingGetting started with performance testing
Getting started with performance testing
 
Presence Agent y Presence Scripting para personas con limitaciones visuales
Presence Agent y Presence Scripting para personas con limitaciones visualesPresence Agent y Presence Scripting para personas con limitaciones visuales
Presence Agent y Presence Scripting para personas con limitaciones visuales
 
Innovation In The Workplace Andrew James
Innovation In The Workplace   Andrew JamesInnovation In The Workplace   Andrew James
Innovation In The Workplace Andrew James
 
New Research: Cloud, Cost & Complexity Impact IAM & IT
New Research: Cloud, Cost & Complexity Impact IAM & ITNew Research: Cloud, Cost & Complexity Impact IAM & IT
New Research: Cloud, Cost & Complexity Impact IAM & IT
 
Dr Ravi Gupta
Dr Ravi GuptaDr Ravi Gupta
Dr Ravi Gupta
 
Top 10 Business Continuity Disasters
Top 10 Business Continuity DisastersTop 10 Business Continuity Disasters
Top 10 Business Continuity Disasters
 
Rsa2012 下一代安全的战略思考-绿盟科技赵粮
Rsa2012 下一代安全的战略思考-绿盟科技赵粮Rsa2012 下一代安全的战略思考-绿盟科技赵粮
Rsa2012 下一代安全的战略思考-绿盟科技赵粮
 
TXT Next Presentation
TXT Next Presentation TXT Next Presentation
TXT Next Presentation
 
Perceptive Software Scope
Perceptive Software ScopePerceptive Software Scope
Perceptive Software Scope
 
Running SagePFW in a Private Cloud
Running SagePFW in a Private CloudRunning SagePFW in a Private Cloud
Running SagePFW in a Private Cloud
 
Pramata Tech Dinosaurs ePaper - Social Sharing
Pramata Tech Dinosaurs ePaper - Social SharingPramata Tech Dinosaurs ePaper - Social Sharing
Pramata Tech Dinosaurs ePaper - Social Sharing
 
5 Reasons to Recycle in the D.C. Metro Area
5 Reasons to Recycle in the D.C. Metro Area5 Reasons to Recycle in the D.C. Metro Area
5 Reasons to Recycle in the D.C. Metro Area
 

Similar to Introduction to package in java

Packages
PackagesPackages
Packages
Monika Mishra
 
Java packags
Java packagsJava packags
Java packags
Padma Kannan
 
7.Packages and Interfaces(MB).ppt .
7.Packages and Interfaces(MB).ppt             .7.Packages and Interfaces(MB).ppt             .
7.Packages and Interfaces(MB).ppt .
happycocoman
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptxTHE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
Kavitha713564
 
Lecture 9 access modifiers and packages
Lecture   9 access modifiers and packagesLecture   9 access modifiers and packages
Lecture 9 access modifiers and packages
manish kumar
 
Packages
PackagesPackages
Packages and interface
Packages and interfacePackages and interface
Packages and interface
KarthigaGunasekaran1
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
pankaj chelak
 
Package in Java
Package in JavaPackage in Java
Package in Java
lalithambiga kamaraj
 
Java packages
Java packagesJava packages
Java packages
GaneshKumarKanthiah
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
talha ijaz
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
222902019
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
222902019
 
Javapackages 4th semester
Javapackages 4th semesterJavapackages 4th semester
Javapackages 4th semester
Varendra University Rajshahi-bangladesh
 
Package.pptx
Package.pptxPackage.pptx
Package.pptx
VeenaNaik23
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
Kuntal Bhowmick
 
Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
Narayana Swamy
 

Similar to Introduction to package in java (20)

Packages
PackagesPackages
Packages
 
Java packags
Java packagsJava packags
Java packags
 
7.Packages and Interfaces(MB).ppt .
7.Packages and Interfaces(MB).ppt             .7.Packages and Interfaces(MB).ppt             .
7.Packages and Interfaces(MB).ppt .
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
 
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptxTHE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
 
Lecture 9 access modifiers and packages
Lecture   9 access modifiers and packagesLecture   9 access modifiers and packages
Lecture 9 access modifiers and packages
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
 
Packages
PackagesPackages
Packages
 
Packages and interface
Packages and interfacePackages and interface
Packages and interface
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
Java packages
Java packagesJava packages
Java packages
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
 
Javapackages 4th semester
Javapackages 4th semesterJavapackages 4th semester
Javapackages 4th semester
 
Package.pptx
Package.pptxPackage.pptx
Package.pptx
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
 

More from Prognoz Technologies Pvt. Ltd.

A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
Prognoz Technologies Pvt. Ltd.
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
Introduction of .net framework
Introduction of .net frameworkIntroduction of .net framework
Introduction of .net framework
Prognoz Technologies Pvt. Ltd.
 
How to handle exceptions in Java Technology
How to handle exceptions in Java Technology How to handle exceptions in Java Technology
How to handle exceptions in Java Technology
Prognoz Technologies Pvt. Ltd.
 
Features of java technology
Features of java technologyFeatures of java technology
Features of java technology
Prognoz Technologies Pvt. Ltd.
 
Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Qualities of a Successful Person
Qualities of a Successful PersonQualities of a Successful Person
Qualities of a Successful Person
Prognoz Technologies Pvt. Ltd.
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Quantitative Aptitude Concepts
Quantitative Aptitude ConceptsQuantitative Aptitude Concepts
Quantitative Aptitude Concepts
Prognoz Technologies Pvt. Ltd.
 

More from Prognoz Technologies Pvt. Ltd. (10)

A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
 
Introduction of .net framework
Introduction of .net frameworkIntroduction of .net framework
Introduction of .net framework
 
How to handle exceptions in Java Technology
How to handle exceptions in Java Technology How to handle exceptions in Java Technology
How to handle exceptions in Java Technology
 
Features of java technology
Features of java technologyFeatures of java technology
Features of java technology
 
Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
 
Qualities of a Successful Person
Qualities of a Successful PersonQualities of a Successful Person
Qualities of a Successful Person
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
 
Quantitative Aptitude Concepts
Quantitative Aptitude ConceptsQuantitative Aptitude Concepts
Quantitative Aptitude Concepts
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

Introduction to package in java

  • 1. © Prognoz Technologies Pvt. Ltd Topic Covered:  Understand the use of casting objects  Understand Packages & Access Specifier  Create static variables, methods, and initializers  Modifiers  Create and use an interface  Inner class & Anonymous class Objectives
  • 2. © Prognoz Technologies Pvt. Ltd 2 Packages  Provide a mechanism for grouping a variety of classes and / or interfaces together.  Grouping is based on functionality. Benefits:  The classes contained in the packages of other programs can be reused.  In packages, classes can be unique compared with classes in other packages.  Packages provides a way to hide classes.
  • 3. © Prognoz Technologies Pvt. Ltd 3 Packages  Two types of packages: 1. Java API packages 2. User defined packages Java API Packages:  A large number of classes grouped into different packages based on functionality. Examples: 1. java.lang 2. java.util 3. java.io 4. java.awt 5.java.net 6.java. applet etc.
  • 4. © Prognoz Technologies Pvt. Ltd 4 Package Color Graphics Image Java awt Package containing awt package Package containing classes
  • 5. © Prognoz Technologies Pvt. Ltd 5 Accessing Classes in a Package 1. Fully Qualified class name: Example:java.awt.Color 2. import packagename.classname; Example: import java.awt.Color; or import packagename.*; Example: import java.awt.*;  Import statement must appear at the top of the file, before any class declaration.
  • 6. 6 Creating Your Own Package 1. Declare the package at the beginning of a file using the form package packagename; 2. Define the class that is to be put in the package and declare it public. 3. Create a subdirectory under the directory where the main source files are stored. 4. Store the listing as classname.java in the subdirectory created. 5. Compile the file. This creates .class file in the subdirectory. Example: package firstPackage; Public class FirstClass { //Body of the class }
  • 7. 7 Example1-Package package p1; public class ClassA { public void displayA( ) { System.out.println(“Class A”); } } import p1.*; Class testclass { public static void main(String str[]) { ClassA obA=new ClassA(); obA.displayA(); } }Source file – ClassA.java Subdirectory-p1 ClassA.Java and ClassA.class->p1 Source file-testclass.java testclass.java and testclass.class->in a directory of which p1 is subdirectory.
  • 8. © Prognoz Technologies Pvt. Ltd 8 Creating Packages  Consider the following declaration: package firstPackage.secondPackage; This package is stored in subdirectory named firstPackage.secondPackage.  A java package can contain more than one class definitions that can be declared as public.  Only one of the classes may be declared public and that class name with .java extension is the source file name.
  • 9. 9 Example2-Package package p2; public class ClassB { protected int m =10; public void displayB() { System.out.println(“Class B”); System.out.println(“m= “+m); } } import p1.*; import p2.*; class PackageTest2 { public static void main(String str[]) { ClassA obA=new ClassA(); Classb obB=new ClassB(); obA.displayA(); obB.displayB(); } }
  • 10. 10 Example 3- Package import p2.ClassB; class ClassC extends ClassB { int n=20; void displayC() { System.out.println(“Class C”); System.out.println(“m= “+m); System.out.println(“n= “+n); } } class PackageTest3 { public static void main(String args[]) { ClassC obC = new ClassC(); obC.displayB(); obC.displayC(); } }
  • 11. 11 Package package p1; public class Teacher {………….} public class Student {……………..} package p2; public class Courses {………..} public class Student {………………..} import p1.*; import p2.*; Student student1; //Error Correct Code: import p1.*; import p2.*; p1.Student student1; p2.Student student2;
  • 12. © Prognoz Technologies Pvt. Ltd 12 Default Package  If a source file does not begin with the package statement, the classes contained in the source file reside in the default package  The java compiler automatically looks in the default package to find classes.
  • 13. © Prognoz Technologies Pvt. Ltd 13 Finding Packages  Two ways: 1.By default, java runtime system uses current directory as starting point and searches all the subdirectories for the package. 2.Specify a directory path using CLASSPATH environmental variable.
  • 14. © Prognoz Technologies Pvt. Ltd 14 CLASSPATH Environment Variable  The compiler and runtime interpreter know how to find standard packages such as java.lang and java.util  The CLASSPATH environment variable is used to direct the compiler and interpreter to where programmer defined imported packages can be found  The CLASSPATH environment variable is an ordered list of directories and files
  • 15. © Prognoz Technologies Pvt. Ltd 15 CLASSPATH Environment Variable  To set the CLASSPATH variable we use the following command: set CLASSPATH=c:  Java compiler and interpreter searches the user defined packages from the above directory.  To clear the previous setting we use: set CLASSPATH=
  • 16. Example1-Package[Using CLASSPATH] package p1; public class ClassA { public void displayA( ) { System.out.println(“Class A”); } } import p1.ClassA; Class PackageTest1 { public static void main(String str[]) { ClassA obA=new ClassA(); obA.displayA(); } } Source file – c:p1ClassA.java Compile-javac c:p1ClassA.java Class file in –c:p1ClassA.class Source file- c:javajdk1.6.0_06binPackageTest1.java Compile-javac PackageTest1.java Copy –PackageTest1.class -> c: Execute-java PackageTest1
  • 17. 17 Example2-Package[Using CLASSPATH] package p2; public class ClassB { protected int m =10; public void displayB() { System.out.println(“Class B”); System.out.println(“m= “+m); } } import p1.*; import p2.*; class PackageTest2 { public static void main(String str[]) { ClassA obA=new ClassA(); Classb obB=new ClassB(); obA.displayA(); obB.displayB(); } } Source file – c:p2ClassB.java Compile-c:p2ClassB.java Class file in –:p2ClassB.class c:javajdk1.6.0_06binPackageTest2.java Compile-javac PackageTest2.java Copy –PackageTest2.class -> c: Execute-java PackageTest2
  • 18. 18 Example 3- Package[Using CLASSPATH] import p2.ClassB; class ClassC extends ClassB { int n=20; void displayC() { System.out.println(“Class C”); System.out.println(“m= “+m); System.out.println(“n= “+n); } } class PackageTest3 { public static void main(String args[]) { ClassC obC = new ClassC(); obC.displayB(); obC.displayC(); } } Source file – c:ClassC.java Compile-c:ClassC.java Class file in –c:ClassC.class Source file-c:javajdk1.6.0_06binPackageTest3.java Compile-javac PackageTest3.java Copy –PackageTest3.class -> c: Execute-java PackageTest3
  • 19. © Prognoz Technologies Pvt. Ltd 19 Adding a Class to a Package  Every java source file can contain only class declared as public.  The name of the source file should be same as the name of the public class with .java extension. package p1; public ClassA{ ……………} Source file : ClassA.java Subdirectory: p1 package p1; public ClassB{…………} Source file: ClassB.java Subdirectory:p1
  • 20. © Prognoz Technologies Pvt. Ltd 20 Adding a Class to a Package  Decide the name of the package.  Create the subdirectory with this name under the directory where the main source file is located.  Create classes to be placed in the package in separate source files and declare the package statement package packagename;  Compile each source file. When completed the package will contain .class files of the source files.
  • 21. © Prognoz Technologies Pvt. Ltd Summary!!