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

แชร์
ฝัง

ความคิดเห็น • 7

  • @sujithg5873
    @sujithg5873 2 ปีที่แล้ว +1

    It’s superb. Waiting for more videos

  • @shyamagrawal3047
    @shyamagrawal3047 2 ปีที่แล้ว +1

    Great Inputs .. Thanks a lot

  • @SRASolution
    @SRASolution 7 หลายเดือนก่อน

    Very nicely explained

  • @jaydeepjena8565
    @jaydeepjena8565 11 หลายเดือนก่อน

    static and transient variable is never take part in serialization process,Can you share code or can bit explain more in details.

    • @technotowntechie9732
      @technotowntechie9732  9 หลายเดือนก่อน

      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 ปีที่แล้ว

    Could you please tell this is for how many yrs experienced profile?