SlideShare una empresa de Scribd logo
1 de 13
ASPIRE. ACHIEVE.
ASCEND
P4UGCA1932U3L6
ProgramminginJAVA
UGCA1932
Programming in JAVA
UNIT 3 LESSON 6
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION HANDLING
Dr Vineet Kumar
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
UNIT 1
✔ L1- One Dimension Array
✔ L2- Two Dimension Array
✔ L3- Strings
✔ L4- String Functions
✔ L5- Interface basics
✔ L6- Interface types
✔ L7- packages
✔ L8- Creating and accessing Packages
✔ L9- Exception Concept
✔ L10- Programs on Exception
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L3 UNIT 3 Lesson 6
Different types of Interfaces
Functional Interface
Examples of Functional Interface
Marker Interface
Cloneable Interface
Serializable Interface
Serializable interface Example
Remote Interface
Remote Interface example
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 6:- INTERFACE TYPES
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L6S1
Different types of Interfaces
1.Functional Interface
2.Marker Interface
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L6S2
Functional Interface is an interface that
has only pure one abstract method.
It can have any number of static and
default methods and also even public
methods of java.lang.Object classes
1.Functional Interface
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
Examples of Functional Interfaces:
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L6S3
When an interface contains only one abstract
method, then it is known as a Functional
Interface.
Examples of Functional Interfaces:
Runnable : It contains only run() method
ActionListener : It contains
only actionPerformed()
ItemListener : It contains
only itemStateChanged() method
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L6S4
2. Marker Interface:
An interface that does not contain any
methods, fields, Abstract Methods, and any
Constants is Called a Marker interface.
Also, if an interface is empty, then it is known
as Marker Interface.
The Serializable and the Cloneable interfaces
are examples of Marker interfaces.
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L5S5
1. Cloneable Interface
A cloneable interface in Java is also a Marker
interface that belongs to java.lang packages.
It generates a replica(copy) of an object with a
different name. Therefore we can implement
the interface in the class of which class object
is to be cloned.
It implements the clone() method of the
Object class to it.
import java.lang.Cloneable;
class abc implements Cloneable
{int x;
String y;
public abc(int x,String y)
{ this.x = x;
this.y = y; }
protected Object clone()
throws CloneNotSupportedException
{ return
super.clone();}
}
public class Test
{ public static void main(String[] args)
throws
CloneNotSupportedException
{
abc p = new abc(10, "We Are Reading GFG Now");
abc q = (abc)p.clone();
System.out.println(q.x);
System.out.println(q.y)
}}
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L5S6
2. Serializable Interface:
It is a marker interface in Java that is defined in the java.io package. If we want
to make the class serializable, we must implement the Serializable interface. If a
class implements the Serializable interface, we can serialize or deserialize the
state of an object of that class.
Serialization is a mechanism in which our object state is ready from memory and
written into a file or from the databases.
Deserialization- is the opposite of serialization means that object state reading
from a file or database and written back into memory is called deserialization of
an object.
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L5S7
import java.io.*;
class A implements Serializable {
int i;
String s;
public A(int i, String s)
{
this.i = i;
this.s = s;
}
}public class Test {
public static void main(String[] args)
throws IOException, ClassNotFoundException
{
A a = new A(20, "GeeksForGeeks");
FileOutputStream fos
= new FileOutputStream("xyz.txt");
ObjectOutputStream oos
= new ObjectOutputStream(fos);
oos.writeObject(a);
FileInputStream fis
= new FileInputStream("xyz.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
A b = (A)ois.readObject(); // down-casting object
System.out.println(b.i + " " + b.s);
oos.close();
ois.close();
}
}
Serializable Interface Example:
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L5S8
3. Remote Interface:
A remote interface is a marker interface that belongs
to java.rmi package. It marks an object as a remote that can be
accessed from the host of another machine.
We need to implement the Remote interface if we want to make an
object remote then. Therefore, It identifies the interface.
A remote interface serves to identify interfaces whose methods may
be invoked from a non-local virtual machine. Any object that is a
remote object must directly or indirectly implement this interface.
The remote interface is an interface that declares the set of methods
that will be invoked from a remote Java Virtual Machine, i.e.(JVM
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
LESSON 5:- INTERFACE BASICS
UNIT 3
ARRAY,STRINGS,INTERFACES ,
PACKAGES & EXCEPTION
HANDLING
P4UGCA1932U3L5S9
3. Remote
Interface Example:
1.Create an interface that extends the
predefined interface Remote which belongs to
the package or, implement the Remote
interface with the class, which you need to
make remote.
2.Declare all the business methods that can
be invoked by the client in this interface.
3.Since there is a chance of network issues
during remote calls, an exception named
RemoteException may occur; throw it.
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
Quiz on lesson
RECAPITULATION
Answers of quiz
A1)Functional,marker,cloneable,serializable
A2) Functional Interface is an interface that
has only pure one abstract method.
A3) An interface that does not contain any methods, fields,
Abstract Methods, and any Constants is Called a Marker
interface
A4) Serialization is a mechanism in which our object state is
ready from memory and written into a file or from the
databases.
1.What are different types of interfaces?
2.What is functional interface?
3.What is marker interface?
4..What is serializable interface?
LESSON 2 :-JAVA INPUT & OUTPUT
UNIT 1. JAVA FUNDAMENTALS &
ESSENTIALS
P4UGCA1932U3L1S8
Different types of Interfaces
Functional Interface
Examples of Functional Interface
Marker Interface
Cloneable Interface
Serializable Interface
Serializable interface Example
Remote Interface
Remote Interface example
Sector 54, Chandigarh, Phase-2,
Mohali - PB
ASPIRE. ACHIEVE.
ASCEND
https://www.geeksforgeeks.org/java/
REFERENCES(URL)
https://www.guru99.com/java-tutorial.html

Más contenido relacionado

Similar a GJIMT BCA P4UGCA1932U3L6.pptx

Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsRohit Singh
 
U3 JAVA.pptx
U3 JAVA.pptxU3 JAVA.pptx
U3 JAVA.pptxmadan r
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 featuresshrinath97
 
Core JAVA presentation for 1st year students
Core JAVA presentation for 1st year studentsCore JAVA presentation for 1st year students
Core JAVA presentation for 1st year studentsSudhanshuVijay3
 
DBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse EngineeringDBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse EngineeringSahil Dhar
 
Java interview questions
Java interview questionsJava interview questions
Java interview questionsSoba Arjun
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Raffi Khatchadourian
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 

Similar a GJIMT BCA P4UGCA1932U3L6.pptx (20)

Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
U3 JAVA.pptx
U3 JAVA.pptxU3 JAVA.pptx
U3 JAVA.pptx
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
What`s new in Java 7
What`s new in Java 7What`s new in Java 7
What`s new in Java 7
 
Core JAVA presentation for 1st year students
Core JAVA presentation for 1st year studentsCore JAVA presentation for 1st year students
Core JAVA presentation for 1st year students
 
DBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse EngineeringDBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse Engineering
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
 
Exploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systemsExploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systems
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Java 7
Java 7Java 7
Java 7
 
Java
JavaJava
Java
 

Último

Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 

Último (20)

FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 

GJIMT BCA P4UGCA1932U3L6.pptx

  • 1. ASPIRE. ACHIEVE. ASCEND P4UGCA1932U3L6 ProgramminginJAVA UGCA1932 Programming in JAVA UNIT 3 LESSON 6 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING Dr Vineet Kumar
  • 2. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND UNIT 1 ✔ L1- One Dimension Array ✔ L2- Two Dimension Array ✔ L3- Strings ✔ L4- String Functions ✔ L5- Interface basics ✔ L6- Interface types ✔ L7- packages ✔ L8- Creating and accessing Packages ✔ L9- Exception Concept ✔ L10- Programs on Exception UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L3 UNIT 3 Lesson 6 Different types of Interfaces Functional Interface Examples of Functional Interface Marker Interface Cloneable Interface Serializable Interface Serializable interface Example Remote Interface Remote Interface example
  • 3. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 6:- INTERFACE TYPES UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L6S1 Different types of Interfaces 1.Functional Interface 2.Marker Interface
  • 4. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L6S2 Functional Interface is an interface that has only pure one abstract method. It can have any number of static and default methods and also even public methods of java.lang.Object classes 1.Functional Interface
  • 5. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS Examples of Functional Interfaces: UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L6S3 When an interface contains only one abstract method, then it is known as a Functional Interface. Examples of Functional Interfaces: Runnable : It contains only run() method ActionListener : It contains only actionPerformed() ItemListener : It contains only itemStateChanged() method
  • 6. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L6S4 2. Marker Interface: An interface that does not contain any methods, fields, Abstract Methods, and any Constants is Called a Marker interface. Also, if an interface is empty, then it is known as Marker Interface. The Serializable and the Cloneable interfaces are examples of Marker interfaces.
  • 7. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L5S5 1. Cloneable Interface A cloneable interface in Java is also a Marker interface that belongs to java.lang packages. It generates a replica(copy) of an object with a different name. Therefore we can implement the interface in the class of which class object is to be cloned. It implements the clone() method of the Object class to it. import java.lang.Cloneable; class abc implements Cloneable {int x; String y; public abc(int x,String y) { this.x = x; this.y = y; } protected Object clone() throws CloneNotSupportedException { return super.clone();} } public class Test { public static void main(String[] args) throws CloneNotSupportedException { abc p = new abc(10, "We Are Reading GFG Now"); abc q = (abc)p.clone(); System.out.println(q.x); System.out.println(q.y) }}
  • 8. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L5S6 2. Serializable Interface: It is a marker interface in Java that is defined in the java.io package. If we want to make the class serializable, we must implement the Serializable interface. If a class implements the Serializable interface, we can serialize or deserialize the state of an object of that class. Serialization is a mechanism in which our object state is ready from memory and written into a file or from the databases. Deserialization- is the opposite of serialization means that object state reading from a file or database and written back into memory is called deserialization of an object.
  • 9. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L5S7 import java.io.*; class A implements Serializable { int i; String s; public A(int i, String s) { this.i = i; this.s = s; } }public class Test { public static void main(String[] args) throws IOException, ClassNotFoundException { A a = new A(20, "GeeksForGeeks"); FileOutputStream fos = new FileOutputStream("xyz.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(a); FileInputStream fis = new FileInputStream("xyz.txt"); ObjectInputStream ois = new ObjectInputStream(fis); A b = (A)ois.readObject(); // down-casting object System.out.println(b.i + " " + b.s); oos.close(); ois.close(); } } Serializable Interface Example:
  • 10. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L5S8 3. Remote Interface: A remote interface is a marker interface that belongs to java.rmi package. It marks an object as a remote that can be accessed from the host of another machine. We need to implement the Remote interface if we want to make an object remote then. Therefore, It identifies the interface. A remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. The remote interface is an interface that declares the set of methods that will be invoked from a remote Java Virtual Machine, i.e.(JVM
  • 11. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND LESSON 5:- INTERFACE BASICS UNIT 3 ARRAY,STRINGS,INTERFACES , PACKAGES & EXCEPTION HANDLING P4UGCA1932U3L5S9 3. Remote Interface Example: 1.Create an interface that extends the predefined interface Remote which belongs to the package or, implement the Remote interface with the class, which you need to make remote. 2.Declare all the business methods that can be invoked by the client in this interface. 3.Since there is a chance of network issues during remote calls, an exception named RemoteException may occur; throw it.
  • 12. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND Quiz on lesson RECAPITULATION Answers of quiz A1)Functional,marker,cloneable,serializable A2) Functional Interface is an interface that has only pure one abstract method. A3) An interface that does not contain any methods, fields, Abstract Methods, and any Constants is Called a Marker interface A4) Serialization is a mechanism in which our object state is ready from memory and written into a file or from the databases. 1.What are different types of interfaces? 2.What is functional interface? 3.What is marker interface? 4..What is serializable interface? LESSON 2 :-JAVA INPUT & OUTPUT UNIT 1. JAVA FUNDAMENTALS & ESSENTIALS P4UGCA1932U3L1S8 Different types of Interfaces Functional Interface Examples of Functional Interface Marker Interface Cloneable Interface Serializable Interface Serializable interface Example Remote Interface Remote Interface example
  • 13. Sector 54, Chandigarh, Phase-2, Mohali - PB ASPIRE. ACHIEVE. ASCEND https://www.geeksforgeeks.org/java/ REFERENCES(URL) https://www.guru99.com/java-tutorial.html