transient « serialize « Java I/O Q&A

1. Can we deny a java object from serialization other than giving transient keyword

We can avoid serialising fields by using the transient keyword. Is there any other way of doing that?

2. Serializable and transient

To make class serializable we do the following:

class A implements Serializable {
    transient Object a;
And why not:
serializable class A {
   transient Object a;
Why if we want ...

3. To initialize a transient field, what is the most simple solution

class MyClass implements Serializable {
  transient int myTransient;
  //Other variables
When I restore this class I want to initialize myTransient manually, but otherwise I just want to use the default ...

4. Java: Static transient fields

I just found out in Java you can declare a field 'static transient' - the compiler doesn't complain. This doesn't seem to be useful in any way since static fields are ...

5. Use of serializable and transient in Java

public class Foo implements {
   private int v1;
   private static double v2;
   private Loan v3 = new Loan();
A. An instance of Foo can be ...

6. What is the use of transient variables?

Possible Duplicate:
Why does Java have transient variables?
The transient keyword will be used to prevent serialization of a particular variable. But why should we not ...

7. Java static serialization rules?

I'm working on a save state serialization with a few static methods and fields. I could have sworn though that serialization and static's caused mayhem. Should I make all static's transient? ...

8. XJC non-transient non-serializable instance field data

After generating java classes I received:

public class myClass {

@XmlElement(name = "Data", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar data;
@XmlElement(name = "Time", required = true)
protected XMLGregorianCalendar time;
FindBugs warns that myClass defines non-transient non-serializable ...

9. Deserialized value of transient int?

public class Employee implements
 public String name;
 public int transient id;

Suppose we are serializing ...
Employee e = new Employee();"REUBEN";;

Now if I deserialize this then
System.out.println("Name: " +; will give ...

10. confusion regarding serialization with static and transient variable

import*; public class TestSer{public static void main (String[] args) { SpecialSerial s=new SpecialSerial(); try { ObjectOutputStream os = new ObjectOutputStream (new FileOutputStream("myFile")); os.writeObject(s); os.close(); System.out.println(s.y + " " +s.z); ObjectInputStream is = new ObjectInputStream(new FileInputStream("myFile")); SpecialSerial s2= (SpecialSerial)is.readObject(); is.close(); System.out.println(s2.y + " " +s2.z); } catch(Exception x) { System.out.println("exc");} } } class SpecialSerial implements Serializable { transient int y=7; static ...

11. why transient variable cannot be serialized

Ok. As an example let us suppose you have a class MyClass that has two Images that were read in from .jpg files. Now, when you serialize your instance of MyClass, you do not want to write the Image objects into it, but rather you would build the Images again when you deserialize your class instance. Does this make sense?

12. serialization and transient

Imagine you have an application that holds User objects. Now if the program is closed, all information would be lost, so you have to find a way to persist data. You could write each property of the User class into a file, separated by comma or something, but that's cumbersome and error prone. Instead, you mark the User class as Serializable, ...

13. Serializable - transient variable

Hi, I've a piece of code which has a transient variable. After de-Serialization I want to get back the value of that transient variable. Can anyone please tell me the way. Thanks in advance! CODE: package pack1; import*; import java.util.Date; public class Logon implements Serializable { private Date date = new Date(); private String username; private transient String password; public ...

15. Serialization & transient attributes

Hello, I'm very new to Java programming and this site, so I apologize if this question has already been asked numerous times. I have to do a project for my intro to java class that is suppose to have binary file I/O in all of our classes we have to do. All of the classes are serializable, however, one of the ...