Legato Interview Questions| Java interview | SpringBoot | MicroServices | MongoDB | Docker | AWS

  Рет қаралды 3,920

Techno Town Techie

Techno Town Techie

Күн бұрын

Пікірлер: 7
@sujithg5873
@sujithg5873 3 жыл бұрын
It’s superb. Waiting for more videos
@shyamagrawal3047
@shyamagrawal3047 2 жыл бұрын
Great Inputs .. Thanks a lot
@SRASolution
@SRASolution Жыл бұрын
Very nicely explained
@jaydeepjena8565
@jaydeepjena8565 Жыл бұрын
static and transient variable is never take part in serialization process,Can you share code or can bit explain more in details.
@technotowntechie9732
@technotowntechie9732 Жыл бұрын
Static Variables: Static variables are class-level variables, shared among all instances of a class. During serialization, static variables are not serialized because they belong to the class, not to individual objects. When deserialized, static variables will contain the values present in the class definition at the time of deserialization. Example: import java.io.*; class MyClass implements Serializable { static int staticVariable = 10; int nonStaticVariable = 20; } public class SerializationExample { public static void main(String[] args) { try { MyClass obj = new MyClass(); obj.staticVariable = 30; // Modify the static variable // Serialize the object FileOutputStream fileOut = new FileOutputStream("object.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(obj); out.close(); fileOut.close(); // Deserialize the object FileInputStream fileIn = new FileInputStream("object.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); MyClass newObj = (MyClass) in.readObject(); in.close(); fileIn.close(); // Print static variable value after deserialization System.out.println("Static variable after deserialization: " + newObj.staticVariable); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } } In this example, the staticVariable is modified before serialization, but after deserialization, its value reverts to the original value defined in the class. Transient Variables: Transient variables are not serialized during the serialization process. When an object is serialized, transient variables are skipped and not included in the serialized representation. When deserialized, transient variables are initialized to their default values. Example: import java.io.*; class MyClass implements Serializable { transient int transientVariable = 100; int nonTransientVariable = 200; } public class SerializationExample { public static void main(String[] args) { try { MyClass obj = new MyClass(); obj.transientVariable = 300; // Modify the transient variable // Serialize the object FileOutputStream fileOut = new FileOutputStream("object.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(obj); out.close(); fileOut.close(); // Deserialize the object FileInputStream fileIn = new FileInputStream("object.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); MyClass newObj = (MyClass) in.readObject(); in.close(); fileIn.close(); // Print transient variable value after deserialization System.out.println("Transient variable after deserialization: " + newObj.transientVariable); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } } In this example, the transientVariable is modified before serialization, but after deserialization, its value reverts to the default value (0 for an integer) because it is marked as transient and is not serialized.
@jagadeeshbaskaran4881
@jagadeeshbaskaran4881 2 жыл бұрын
Could you please tell this is for how many yrs experienced profile?
@technotowntechie9732
@technotowntechie9732 2 жыл бұрын
5 years
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
MUST KNOW junior role JAVA interview questions
42:15
Keep On Coding
Рет қаралды 140 М.
NGINX Explained - What is Nginx
14:32
TechWorld with Nana
Рет қаралды 303 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.