selwee
Answered On : Apr 2nd, 2006
Yes we can serialize the static variable.if u don't want to serialize, u need to declare the variable as transient
Login to rate this answer.
We cannot serialize static and transient variables. We serialize objects to store them so they can retrieved later for any use.
Login to rate this answer.
yes we can serialize this but how to do this which time i required this
Login to rate this answer.
Mohana
Answered On : Apr 7th, 2006
I hope static/transient variables are not serializable
Login to rate this answer.
Manjunath N
Answered On : Apr 14th, 2006
No, we can serialize static , transient, final variables and methods or variables in the final classes.
Login to rate this answer.
By default static variables are not serializable.This is due to the reason that they are not bound to a particular object.If u want to exclude an ordinary variable from serialization then qualify that variable as transient
Login to rate this answer.
vasanta
Answered On : May 8th, 2006
Plz stop to give the stupid answers If u know perfect answers then u can post.Plz dont confuse others by seeing those
Login to rate this answer.
No,
we cannot.
We cannot serialize the static and transient variables.

2 Users have rated as useful.
Login to rate this answer.
Please go to this link and read about serializationhttp://java.sun.com/docs/books/tutorial/essential/io/providing.html.It's should clear everything
Login to rate this answer.
Rajnish Kumar
Answered On : May 13th, 2006
no we cant serialize the static variable
Login to rate this answer.
srinivas
Answered On : May 21st, 2006
Hi
This is possible by providing the following two methods in our class
as shown below. writeObject(),readObject().
import java.io.*;
public class Ab
{
public static void main(String a[])
throws Exception
{
FileOutputStream fos = new FileOutputStream("data.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
Abc1 a1 = new Abc1();
a1.i = 25;
a1.j = 35;
a1.k = "srinivas";
oos.writeObject(a1);
fos.close();
}
}
import java.io.*;
public class Abc1 implements Serializable
{public int i;
public static float j;
public static String k;
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
{
System.out.println("writeObject");
out.writeInt(i);out.writeFloat(j);
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException
{
System.out.println("readObject");
i= in.readInt();
j= in.readFloat();
}
}
ok bye...................
keeps smiling and mailing
if any want java material & doubts regarding j2se ,j2ee plz send mail to
bora_srinivasarao@yahoo.co.in
Note:If possible I will clarify doubts.but I send java material.
Login to rate this answer.
Abhijit
Answered On : May 24th, 2006
Yes .refer Thinking in java Bruce Eckel Page No:633 Version-2 for detailed example on serializing static variables
Login to rate this answer.
radhika
Answered On : Jun 14th, 2006
Several techniques are available to protect sensitive data in classes. The easiest is to mark fields that contain sensitive data as private transient. transient and static fields are not serialized or deserialized. Marking the field will prevent the state from appearing in the stream and from being restored during deserialization. Since writing and reading (of private fields) cannot be superseded outside of the class, the class's transient fields are safe.
Login to rate this answer.
These two links will clear all your doubts: -http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=3http://www.allapplabs.com/interview_questions/java_interview_questions_3.htm#q17
Login to rate this answer.
kiran kumar k
Answered On : Oct 9th, 2006
which one we have to confirm if one guy is sending means tell i know 100%like that
Login to rate this answer.
gopikrishna
Answered On : Nov 2nd, 2006
u r right vasantha... plz give the correct answer.
Login to rate this answer.
No.we can't initialize the static variable.
Login to rate this answer.
Yes we can serialize the static variable as i have checked on system but theory is telling we cant ..can anyone make it clear
Login to rate this answer.
No static variables can't be serialzed......
any doubts, let me know i can give an example???
Login to rate this answer.
Ashish
Answered On : May 21st, 2012
static variable can not be serialized.... please follow find below example.
Test3==>
Code
package a.b.c.d.e;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import a.b.c.d.Test2;
public class Test3 {
/**
* @param args
*/
public static void main
(String[] args
) {
// TODO Auto-generated method stub
Test2 t= new Test2();
Test2.setVar("Test2");
t.setTestVar("Ashish");
Test3 t3 = new Test3();
try {
t3.writeObject(t);
// TODO Auto-generated catch block
e.printStackTrace();
}
Test2.setVar("Test3");
try {
t = t3.readObject();
System.
out.
println(t.
getTestVar()+"==="+t.
getVar());
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* This is the default implementation of writeObject.
* Customise if necessary.
*/
out.writeObject(t);
out.close();
}
Test2 t = (Test2)out.readObject();
out.close();
return t;
}
}
Test2=====>
package a.b.c.d;
import java.io.Serializable;
private static String var
= "Test";
return testVar;
}
public void setTestVar
(String testVar
) {
this.testVar = testVar;
}
public static String getVar
() {
return var;
}
public static void setVar
(String var
) {
Test2.var = var;
}
}
Login to rate this answer.