SlideShare a Scribd company logo
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
ADVANTAGES AND DISADVANTAGES
HOW DO WE SERIALIZE AN OBJECT?
WHY DO WE NEED SERIALIZATION?
WHAT IS SERIALIZATION?
CONTROVERSIES ON SERIALIZATION
BEST PRACTICES
WHAT IS SERIALIZATION?
www.edureka.co
JVM-1 JVM-2
Byte Stream
Object Object
Byte Stream
WHAT IS SERIALIZATION?
www.edureka.co
www.edureka.co
Serialization in Java is the process of converting the Java code
Object into a Byte Stream, to transfer the Object Code from one
Java Virtual machine to another and recreate it using the process
of Deserialization.
WHY DO WE NEED SERIALIZATION?
www.edureka.co
WHY DO WE NEED SERIALIZATION?
Persistence
Deep Copy
Caching
Cross JVM Synchronization
Communication
www.edureka.co
HOW DO WE SERIALIZE AN OBJECT?
www.edureka.co
www.edureka.co
To Serialize an object, the parent class should implement
either of the following interfaces:
• java.io.Serializable
• java.io.Externalizable
HOW DO WE SERIALIZE AN OBJECT?
ADVANTAGES AND DISADVANTAGES
www.edureka.co
ADVANTAGES
• Serialization process does not require third-party
software.
• The Serialization procedure is simple .
• Serialization procedure is universal .
• It is easy to use and simple to customize.
• Serialized data streams support Encryption,
Compression, Authentication and secure Java
computing.
• Many critical technologies relying on serialization.
www.edureka.co
DISADVANTAGES
• Objects while Deserialization becomes brittle.
• Serialization results in the failure in the initialization of
transient variables resulting in a variation to the
Standard Java Flow.
• Serialization is inefficient in terms of memory
utilization.
• Serialization does not offer any transition control
mechanism per every SE.
• Serialization procedure fails to offer fine-grained
control to access Objects.
www.edureka.co
PRACTICAL EXAMPLES
www.edureka.co
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
SERIALIZATION USING INHERITANCE
CASE - 1
www.edureka.co
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
SERIALIZATION USING INHERITANCE
CASE - 2
www.edureka.co
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
SERIALIZATION USING INHERITANCE
CASE - 3
www.edureka.co
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
SERIALIZATION USING A
STATIC MEMBER
www.edureka.co
EXTERNALIZABLE INTERFACE
www.edureka.co
Implementation
Methods
Process Public No-Arg Constructor
Backward Compatibility
EXTERNALIZABLE INTERFACE
www.edureka.co
www.edureka.co
• While using Externalizable Interface the user
explicitly mentions the objects to be serialized.
• In Serialization Interface, all the objects and variables are
serialized in the run-time.
IMPLEMENTATION
www.edureka.co
• Externalizable interface consists of two methods, namely:
writeExternal()
readExternal()
• Serializable Interface does not include any methods.
METHODS
www.edureka.co
• Externalizable Interface provides customization to the
Serialization process.
• Serialization Interface will provide the default serialization
process.
PROCESS
www.edureka.co
• Externalizable Interface supports Serialization
regardless of the version control.
• Serialization Interface requires the same version of
JVMs on both the ends, but it incorporates automatic
serialization.
BACKWARD COMPATABILITY
www.edureka.co
• Externalization Interface needs Public No-Arg Constructor to
reconstruct the serialized object.
• Serialization Interface uses reflection to reconstruct the
serialized object or class.
PUBLIC NO-ARG CONSTRUCTOR
TRANSIENT KEYWORD
www.edureka.co
www.edureka.co
TRANSIENT KEYWORD
Transient Keyword
www.edureka.co
www.edureka.co
TRANSIENT KEYWORD
Transient Keyword
Transient Keyword is used as a variable modifier at the time of
the Serialization process. Declaring a variable with transient
keyword avoids the variable from being Serialized.
TRANSIENTKEYWORD
SERIAL VERSION UID
www.edureka.co
www.edureka.co
SERIAL VERSION UID
Serializable objects get associated with a unique identification
number provided by the JVM of the host machine. This Unique
ID is called Serial Version UID.
SERIALVERSIONUID
CONTROVERSIES ON SERIALIZATION
www.edureka.co
www.edureka.co
WHAT IS AN INHERITANCE?
Oracle’s Architects intend to remove Serialization from Java as
they consider it as a Horrible Mistake of 1997.
After hectic research, the developers at Oracle found out a few
flaws in the design of Serialization procedure which pose a
threat to the data.
BEST PRACTICES
www.edureka.co
BEST PRACTICES
• It is recommended use javadoc@ serial tag for
denoting Serializable fields.
• The .ser extension is preferred to be used for files
representing serialized objects.
• It is not recommended for any static or transient
fields to undergo default serialization.
• Extendable classes should not be Serialized unless it
is mandatory.
• Inner Classes should be avoided to be involved in
Serialization.
www.edureka.co
www.edureka.co

More Related Content

What's hot

String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
imypraz
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 

What's hot (20)

Java package
Java packageJava package
Java package
 
Java threads
Java threadsJava threads
Java threads
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Stack
StackStack
Stack
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Similar to What is Serialization in Java? | Java Tutorial | Edureka

Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
WO Community
 
Design patterns
Design patternsDesign patterns
Design patterns
Alok Guha
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
10322210023
 
Java serialization
Java serializationJava serialization
Java serialization
Sujit Kumar
 

Similar to What is Serialization in Java? | Java Tutorial | Edureka (20)

Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java Deserialization
 
13243967
1324396713243967
13243967
 
Design patterns
Design patternsDesign patterns
Design patterns
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
 
Server Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
BarcelonaJUG - Revolutionize Java Database Application Development with React...
BarcelonaJUG - Revolutionize Java Database Application Development with React...BarcelonaJUG - Revolutionize Java Database Application Development with React...
BarcelonaJUG - Revolutionize Java Database Application Development with React...
 
How Java 19 Influences the Future of Your High-Scale Applications .pdf
How Java 19 Influences the Future of Your High-Scale Applications .pdfHow Java 19 Influences the Future of Your High-Scale Applications .pdf
How Java 19 Influences the Future of Your High-Scale Applications .pdf
 
Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...
Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...
Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...
 
P20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptxP20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptx
 
Java serialization
Java serializationJava serialization
Java serialization
 
DWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads
DWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ThreadsDWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads
DWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
 
JavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGIJavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGI
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...
CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...
CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...
 
Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 

More from Edureka!

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

What is Serialization in Java? | Java Tutorial | Edureka