SlideShare a Scribd company logo
PACKAGES
Dr.K.Kalaiselvi
Dept.of Computer Science
Kristu Jayanti college,
Bangalore
• Package in Java is a mechanism to encapsulate a group of classes, sub
packages and interfaces.
• Packages are used for:
• Preventing naming conflicts. For example there can be two classes
with same name in two packages,
• Makes searching/locating and usage of classes, interfaces,
enumerations and annotations easier
• Providing controlled access: protected and default have package level
access control. Aprotected member is accessible by classes in the
same package and its subclasses. Adefault member (without any
access specifier) is accessible by classes in the same package only.
• Packages that are inside another package are the subpackages. These
are not imported by default, they have to imported explicitly.
User-defined packages
These are the packages that are defined by the user. First we create a
directory mypack . Then create the class Simple inside the directory with the first
statement being the package names.
//save as Simple.java
package mypack;
class SimplePackage{
public void display(){
System.out.println("Welcome to package");
}
}
import mypack.SimplePackage;
public class PackageUse
{
public static void main(String args[])
{
SimplePackage p=new SimplePackage();
p.display();
}
}
To compile java package:
javac -d . Simple.java / / -d specifies the destination where to putthe
generated class file, to keep the package within the same directory use . (dot).
To Compile: javac -d . Simple.java
To Run: java mypack.Simple
• It is a collection of abstract methods. Aclass implements an interface, thereby
inheriting the abstract methods of the interface.
• Interface cannot be instantiated.
• An interface does not contain any constructors.
• All of the methods in an interface are abstract.
• An interface is not extended by a class; it is implemented by a class.
• An interface can extend multiple interfaces.
• Interface methods do not have a body - the body is provided by the
"implement" class
• On implementation of an interface, you must override all of its methods
• Interface methods are by default abstract and public
• Interface attributes are by default public, static and final
• To achieve security - hide certain details and only show the important details
of an object
• "multiple inheritance" can be achieved with interfaces, because the class
can implement multiple interfaces.
INTERFACES IN JA
V
A
by default.
interface <interface_name>{
/ / declare constant fields
/ / declare methods thatabstract
}
The Java compiler adds public and abstract keywords before the interface
method. Moreover, it adds public, static and final keywords before data
members.
a class extends another class, an interface extends another interface, but
a class implements an interface.
Aclass can extend only one class, but implement many interfaces..
interface In1
{
/ / public, static andfinal final int a =
10;
/ / public and abstract void
display();
}
class InterfaceTestClass implements In1
{
/ / Implementing the capabilities of interface.
public void display()
{
System.out.println(“Kristu Jayanti College");
}
public static void main (String[] args)
{
InterfaceTestClass t = new InterfaceTestClass(); t.display();
System.out.println(a);
}
• Aclass can implement more than one interface at a time.
• Aclass can extend only one class, but implement many interfaces.
• An interface can extend another interface, in a similar wayas a class can
extend another class.
• If a class implements multiple interfaces, or an interface extends multiple
interfaces, it is known as multiple inheritance.
interface FirstInterface {
public void myMethod(); / / interface method
}
interface SecondInterface {
public void myOtherMethod(); / / interface method
}
class DemoClass implements FirstInterface, SecondInterface {
public void myMethod() {
System.out.println("Some text from irst interface..");
}
public void myOtherMethod() { System.out.println("Some
text from second interface...");
}
}
class MulInterfaceTest1 {
public static void main(String[] args) {
DemoClass myObj = new DemoClass();
myObj.myMethod();
myObj.myOtherMethod();
}
• Multiple inheritance is not supported through class in java, but it is possible by an
interface, why?
• multiple inheritance is not supported in the case of class because of ambiguity. However,
it is supported in case of an interface because there is no ambiguity. It is because its
implementation is provided by the implementation class.
interface Printable{
void print();
}
interface Showable{
void print();
}
class TestInterface3 implementss Printable, Showable{
public void print(){System.out.println("Hello");}
public static void main(String args[]){
TestInterface3 obj = new TestInterface3();
obj.print();
} }
interface Printable{
void print();
}
interface Showable extends Printable{
void show();
}
class InterfaceInheritance implements Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
InterfaceInheritance obj = new InterfaceInheritance();
obj.print();
obj.show();
}
}
INTERFACE INHERITANCE
Provides classes that are fundamental to the design of the Java programming
language.
Object, the ultimate superclass of all classes in Java
• Thread, the class that controls each thread in a multithreaded program
• Throwable, the superclass of all error and exception classes in Java
• Classes that encapsulate the primitive data types in Java
• Classes for accessing system resources and other low-level entities
• Math, a class that provides standard mathematical methods
• String, the class that is used to represent strings
Java.lang Package In Java
• Wrapper classes are those whose objects wraps a primitive data type within
them.
• In the java.lang package java provides a separate class for each of the
primitive data types namely Byte, Character, Double, Integer, Float, Long,
Short.
• At the time of instantiation, these classes accept a primitive datatype
directly, and wrap a primitive value into a wrapper class object.
• They convert primitive data types into objects.
• It contains the utility classes (a string tokenizer, a random-number generator, and a bit
array).
• AbstractCollection: This class provides a skeletal implementation of the Collection
interface, to minimize the effort required to implement this interface.
• Arrays: This class contains various methods for manipulating arrays (such as sorting and
searching).
• Calendar: The Calendar class is an abstract class that provides methods for converting
between a specific instant in time and a set of calendar fields such as YEAR, MONTH,
DAY_OF_MONTH, HOUR,
• Currency: Represents a currency.
• Date: The class Date represents a specific instant in time, with millisecond precision.
• Random: An instance of this class is used to generate a stream of pseudorandom
numbers.
• Scanner: Asimple text scanner which can parse primitive types and strings using regular
expressions.
• String Tokenizer: The string tokenizer class allows an application to break a string into
tokens.
• Treeset: ANavigableSet implementation based on a TreeMap.
java.util PACKAGE
• This package provides for system input and output through data streams,
serialization and the file system.
• Java uses the concept of a stream to make I/O operation fast. The java.io
package contains all the classes required for input and output operations.
3 streams are created automatically.All these streams are attached with the
console.
1) System.out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream
JAVA.IOPACKAGEIN JA
V
A
Java.io.FileInputStream Class in Java
FileInputStream is useful to read data from a file in the form of sequence of
bytes.For reading streams of characters, consider using FileReader.
Constructor and Description
FileInputStream(File file) :Creates an input file stream to read from the
specified File object.
FileInputStream(FileDescriptor fdobj) :Creates an input file stream to read
from the specified file descriptor.
FileInputStream(String name) :Creates an input file stream to read from a file
with the specified name.
Important Methods:
int read() :Reads a byte of data from this input stream
int read(byte[] b) :Reads up to b.length bytes of data from this input stream into
an array of bytes.
int read(byte[] b, int off, int len) : Reads up to len bytes of data from this input
stream into an array of bytes.
void close() :Closes this file input stream and releases any system resources
associated with the stream.
• FileOutputStream is meant for writing streams of raw bytes
• It can be used to create text files.Afile represents storage of data on a
second storage media like a hard disk or CD. Whether or not a file is
available or may be created
void close() :Closes this file output stream and releases any system resources
associated with this stream.
protected void finalize() :Cleans up the connection to the file, and ensures
that the close method of this file output stream is called when there are no
more references to this stream.
void write(byte[] b) :Writes b.length bytes from the specified byte array to
this file output stream.
void write(byte[] b, int off, int len) :Writes len bytes from the specified
byte array starting at offset off to this file output stream.
void write(int b) :Writes the specified byte to this file output stream.

More Related Content

What's hot

packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
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
 
Java packages
Java packagesJava packages
Java packages
Jeffrey Quevedo
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
Arindam Ghosh
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
AkashDas112
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
java packages
java packagesjava packages
java packages
aptechsravan
 
Interface
InterfaceInterface
Interface
kamal kotecha
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
manish kumar
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
Madishetty Prathibha
 

What's hot (20)

packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Java packages
Java packagesJava packages
Java packages
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
java packages
java packagesjava packages
java packages
 
Interface
InterfaceInterface
Interface
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 

Similar to Unit3 packages &amp; interfaces

Cse java
Cse javaCse java
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
ambikavenkatesh2
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
Hamid Ghorbani
 
Java mcq
Java mcqJava mcq
Java mcq
avinash9821
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
ansariparveen06
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
Tushar Desarda
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
YakaviBalakrishnan
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
bca23189c
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
Khizar40
 
Java interface
Java interfaceJava interface
Java interface
GaneshKumarKanthiah
 

Similar to Unit3 packages &amp; interfaces (20)

Cse java
Cse javaCse java
Cse java
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Java mcq
Java mcqJava mcq
Java mcq
 
Inheritance
InheritanceInheritance
Inheritance
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
Java interface
Java interfaceJava interface
Java interface
 

More from Kalai Selvi

cloud services and providers
cloud services and providerscloud services and providers
cloud services and providers
Kalai Selvi
 
cloud concepts and technologies
cloud concepts and technologiescloud concepts and technologies
cloud concepts and technologies
Kalai Selvi
 
cloud computing
cloud computingcloud computing
cloud computing
Kalai Selvi
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
Kalai Selvi
 
I semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptxI semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptx
Kalai Selvi
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
Kalai Selvi
 
Multimedia Authoring Tools.ppt
Multimedia Authoring Tools.pptMultimedia Authoring Tools.ppt
Multimedia Authoring Tools.ppt
Kalai Selvi
 
Process of Making Multimedia.ppt
Process of Making Multimedia.pptProcess of Making Multimedia.ppt
Process of Making Multimedia.ppt
Kalai Selvi
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
Kalai Selvi
 
Searching techniques in AI
Searching techniques in AISearching techniques in AI
Searching techniques in AI
Kalai Selvi
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
Kalai Selvi
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
Kalai Selvi
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
Kalai Selvi
 
Unit 1 part 2
Unit 1  part 2Unit 1  part 2
Unit 1 part 2
Kalai Selvi
 
Unit 1 part 1
Unit 1   part 1Unit 1   part 1
Unit 1 part 1
Kalai Selvi
 
Unit 4 combinational circuit
Unit 4 combinational circuitUnit 4 combinational circuit
Unit 4 combinational circuit
Kalai Selvi
 
Unit 3 file management
Unit 3 file managementUnit 3 file management
Unit 3 file management
Kalai Selvi
 
Unit 3 chapter 1-file management
Unit 3 chapter 1-file managementUnit 3 chapter 1-file management
Unit 3 chapter 1-file management
Kalai Selvi
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt complete
Kalai Selvi
 

More from Kalai Selvi (19)

cloud services and providers
cloud services and providerscloud services and providers
cloud services and providers
 
cloud concepts and technologies
cloud concepts and technologiescloud concepts and technologies
cloud concepts and technologies
 
cloud computing
cloud computingcloud computing
cloud computing
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
 
I semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptxI semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptx
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
 
Multimedia Authoring Tools.ppt
Multimedia Authoring Tools.pptMultimedia Authoring Tools.ppt
Multimedia Authoring Tools.ppt
 
Process of Making Multimedia.ppt
Process of Making Multimedia.pptProcess of Making Multimedia.ppt
Process of Making Multimedia.ppt
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
 
Searching techniques in AI
Searching techniques in AISearching techniques in AI
Searching techniques in AI
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
 
Unit 1 part 2
Unit 1  part 2Unit 1  part 2
Unit 1 part 2
 
Unit 1 part 1
Unit 1   part 1Unit 1   part 1
Unit 1 part 1
 
Unit 4 combinational circuit
Unit 4 combinational circuitUnit 4 combinational circuit
Unit 4 combinational circuit
 
Unit 3 file management
Unit 3 file managementUnit 3 file management
Unit 3 file management
 
Unit 3 chapter 1-file management
Unit 3 chapter 1-file managementUnit 3 chapter 1-file management
Unit 3 chapter 1-file management
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt complete
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
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
 
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
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
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
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
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
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
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 French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
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.
 
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
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
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...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
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
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
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 French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Unit3 packages &amp; interfaces

  • 2. • Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces. • Packages are used for: • Preventing naming conflicts. For example there can be two classes with same name in two packages, • Makes searching/locating and usage of classes, interfaces, enumerations and annotations easier • Providing controlled access: protected and default have package level access control. Aprotected member is accessible by classes in the same package and its subclasses. Adefault member (without any access specifier) is accessible by classes in the same package only. • Packages that are inside another package are the subpackages. These are not imported by default, they have to imported explicitly.
  • 3.
  • 4.
  • 5. User-defined packages These are the packages that are defined by the user. First we create a directory mypack . Then create the class Simple inside the directory with the first statement being the package names. //save as Simple.java package mypack; class SimplePackage{ public void display(){ System.out.println("Welcome to package"); } }
  • 6. import mypack.SimplePackage; public class PackageUse { public static void main(String args[]) { SimplePackage p=new SimplePackage(); p.display(); } } To compile java package: javac -d . Simple.java / / -d specifies the destination where to putthe generated class file, to keep the package within the same directory use . (dot). To Compile: javac -d . Simple.java To Run: java mypack.Simple
  • 7.
  • 8. • It is a collection of abstract methods. Aclass implements an interface, thereby inheriting the abstract methods of the interface. • Interface cannot be instantiated. • An interface does not contain any constructors. • All of the methods in an interface are abstract. • An interface is not extended by a class; it is implemented by a class. • An interface can extend multiple interfaces. • Interface methods do not have a body - the body is provided by the "implement" class • On implementation of an interface, you must override all of its methods • Interface methods are by default abstract and public • Interface attributes are by default public, static and final • To achieve security - hide certain details and only show the important details of an object • "multiple inheritance" can be achieved with interfaces, because the class can implement multiple interfaces. INTERFACES IN JA V A
  • 9. by default. interface <interface_name>{ / / declare constant fields / / declare methods thatabstract } The Java compiler adds public and abstract keywords before the interface method. Moreover, it adds public, static and final keywords before data members.
  • 10. a class extends another class, an interface extends another interface, but a class implements an interface. Aclass can extend only one class, but implement many interfaces..
  • 11. interface In1 { / / public, static andfinal final int a = 10; / / public and abstract void display(); } class InterfaceTestClass implements In1 { / / Implementing the capabilities of interface. public void display() { System.out.println(“Kristu Jayanti College"); } public static void main (String[] args) { InterfaceTestClass t = new InterfaceTestClass(); t.display(); System.out.println(a); }
  • 12. • Aclass can implement more than one interface at a time. • Aclass can extend only one class, but implement many interfaces. • An interface can extend another interface, in a similar wayas a class can extend another class. • If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.
  • 13. interface FirstInterface { public void myMethod(); / / interface method } interface SecondInterface { public void myOtherMethod(); / / interface method } class DemoClass implements FirstInterface, SecondInterface { public void myMethod() { System.out.println("Some text from irst interface.."); } public void myOtherMethod() { System.out.println("Some text from second interface..."); } } class MulInterfaceTest1 { public static void main(String[] args) { DemoClass myObj = new DemoClass(); myObj.myMethod(); myObj.myOtherMethod(); }
  • 14. • Multiple inheritance is not supported through class in java, but it is possible by an interface, why? • multiple inheritance is not supported in the case of class because of ambiguity. However, it is supported in case of an interface because there is no ambiguity. It is because its implementation is provided by the implementation class. interface Printable{ void print(); } interface Showable{ void print(); } class TestInterface3 implementss Printable, Showable{ public void print(){System.out.println("Hello");} public static void main(String args[]){ TestInterface3 obj = new TestInterface3(); obj.print(); } }
  • 15. interface Printable{ void print(); } interface Showable extends Printable{ void show(); } class InterfaceInheritance implements Showable{ public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]){ InterfaceInheritance obj = new InterfaceInheritance(); obj.print(); obj.show(); } } INTERFACE INHERITANCE
  • 16. Provides classes that are fundamental to the design of the Java programming language. Object, the ultimate superclass of all classes in Java • Thread, the class that controls each thread in a multithreaded program • Throwable, the superclass of all error and exception classes in Java • Classes that encapsulate the primitive data types in Java • Classes for accessing system resources and other low-level entities • Math, a class that provides standard mathematical methods • String, the class that is used to represent strings Java.lang Package In Java
  • 17. • Wrapper classes are those whose objects wraps a primitive data type within them. • In the java.lang package java provides a separate class for each of the primitive data types namely Byte, Character, Double, Integer, Float, Long, Short. • At the time of instantiation, these classes accept a primitive datatype directly, and wrap a primitive value into a wrapper class object. • They convert primitive data types into objects.
  • 18.
  • 19. • It contains the utility classes (a string tokenizer, a random-number generator, and a bit array). • AbstractCollection: This class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface. • Arrays: This class contains various methods for manipulating arrays (such as sorting and searching). • Calendar: The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, • Currency: Represents a currency. • Date: The class Date represents a specific instant in time, with millisecond precision. • Random: An instance of this class is used to generate a stream of pseudorandom numbers. • Scanner: Asimple text scanner which can parse primitive types and strings using regular expressions. • String Tokenizer: The string tokenizer class allows an application to break a string into tokens. • Treeset: ANavigableSet implementation based on a TreeMap. java.util PACKAGE
  • 20. • This package provides for system input and output through data streams, serialization and the file system. • Java uses the concept of a stream to make I/O operation fast. The java.io package contains all the classes required for input and output operations. 3 streams are created automatically.All these streams are attached with the console. 1) System.out: standard output stream 2) System.in: standard input stream 3) System.err: standard error stream JAVA.IOPACKAGEIN JA V A
  • 21. Java.io.FileInputStream Class in Java FileInputStream is useful to read data from a file in the form of sequence of bytes.For reading streams of characters, consider using FileReader. Constructor and Description FileInputStream(File file) :Creates an input file stream to read from the specified File object. FileInputStream(FileDescriptor fdobj) :Creates an input file stream to read from the specified file descriptor. FileInputStream(String name) :Creates an input file stream to read from a file with the specified name. Important Methods: int read() :Reads a byte of data from this input stream int read(byte[] b) :Reads up to b.length bytes of data from this input stream into an array of bytes. int read(byte[] b, int off, int len) : Reads up to len bytes of data from this input stream into an array of bytes. void close() :Closes this file input stream and releases any system resources associated with the stream.
  • 22. • FileOutputStream is meant for writing streams of raw bytes • It can be used to create text files.Afile represents storage of data on a second storage media like a hard disk or CD. Whether or not a file is available or may be created void close() :Closes this file output stream and releases any system resources associated with this stream. protected void finalize() :Cleans up the connection to the file, and ensures that the close method of this file output stream is called when there are no more references to this stream. void write(byte[] b) :Writes b.length bytes from the specified byte array to this file output stream. void write(byte[] b, int off, int len) :Writes len bytes from the specified byte array starting at offset off to this file output stream. void write(int b) :Writes the specified byte to this file output stream.