SlideShare une entreprise Scribd logo
1  sur  22
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.

Contenu connexe

Tendances

Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
backdoor
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
Arjun Shanka
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 

Tendances (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
 

Similaire à Unit3 packages &amp; interfaces

Java tutorials
Java tutorialsJava tutorials
Java tutorials
saryu2011
 

Similaire à 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
 

Plus de Kalai Selvi

Plus de 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
 

Dernier

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

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.