Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What is Serialization in Java? | Java Tutorial | Edureka

118 views

Published on

YouTube Link: https://youtu.be/6B6vp0jZnb0
**https://www.edureka.co/java-j2ee-training-course **
This Edureka video on Serialization in Java will provide you with detailed knowledge about how the Serialization process in Java takes place along with the practical examples for a better understanding.

What is Serialization?
Why do we need Serialization?
How do we Serialize an Object?
Advantages and Disadvantages
Controversies on Serialization
Best Practices.

Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in

Published in: Technology
  • Be the first to comment

  • Be the first to like this

What is Serialization in Java? | Java Tutorial | Edureka

  1. 1. Copyright © 2017, edureka and/or its affiliates. All rights reserved.
  2. 2. 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
  3. 3. WHAT IS SERIALIZATION? www.edureka.co
  4. 4. JVM-1 JVM-2 Byte Stream Object Object Byte Stream WHAT IS SERIALIZATION? www.edureka.co
  5. 5. 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.
  6. 6. WHY DO WE NEED SERIALIZATION? www.edureka.co
  7. 7. WHY DO WE NEED SERIALIZATION? Persistence Deep Copy Caching Cross JVM Synchronization Communication www.edureka.co
  8. 8. HOW DO WE SERIALIZE AN OBJECT? www.edureka.co
  9. 9. 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?
  10. 10. ADVANTAGES AND DISADVANTAGES www.edureka.co
  11. 11. 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
  12. 12. 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
  13. 13. PRACTICAL EXAMPLES www.edureka.co
  14. 14. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co SERIALIZATION USING INHERITANCE CASE - 1 www.edureka.co
  15. 15. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co SERIALIZATION USING INHERITANCE CASE - 2 www.edureka.co
  16. 16. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co SERIALIZATION USING INHERITANCE CASE - 3 www.edureka.co
  17. 17. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co SERIALIZATION USING A STATIC MEMBER www.edureka.co
  18. 18. EXTERNALIZABLE INTERFACE www.edureka.co
  19. 19. Implementation Methods Process Public No-Arg Constructor Backward Compatibility EXTERNALIZABLE INTERFACE www.edureka.co
  20. 20. 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
  21. 21. www.edureka.co • Externalizable interface consists of two methods, namely: writeExternal() readExternal() • Serializable Interface does not include any methods. METHODS
  22. 22. www.edureka.co • Externalizable Interface provides customization to the Serialization process. • Serialization Interface will provide the default serialization process. PROCESS
  23. 23. 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
  24. 24. 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
  25. 25. TRANSIENT KEYWORD www.edureka.co
  26. 26. www.edureka.co TRANSIENT KEYWORD Transient Keyword www.edureka.co
  27. 27. 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
  28. 28. SERIAL VERSION UID www.edureka.co
  29. 29. 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
  30. 30. CONTROVERSIES ON SERIALIZATION www.edureka.co
  31. 31. 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.
  32. 32. BEST PRACTICES www.edureka.co
  33. 33. 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
  34. 34. www.edureka.co

×