answersLogoWhite

0


Best Answer

No, static variables are not serialized.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Ir

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Are static variables serialized in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


Can transient variables be declared as 'final' or 'static'?

Transient Variables are those that do not get serialized during the Serialization process. A Static variable is one that is mapped to the Class and is not mapped to any object instance and hence they would not get serialized. So, there should be no problem with declaring a transient variable as static. On the other hand, A final variable is one that's value cannot change. So if you declare a final variable as transient, it would get stored as null during serialization and when you try to de-serialize the variable, you will get errors because, the variable is final and you cannot assign values for it and it is saved as null during serialization. Result: Yes you can have static transient variables but not final transient variables.


Which one executed first static block or static methods in java?

Static Blocks are always executed first. A static block is executed when your class is charged but a static method is executed only when is called, therefor first the class is charged and then is executed a method.


What is static java most commonly used for?

Static java method is the same as a static variable. They belong to a class and not an object of that class. If a method needs to be in a class, but not tied to an object, then one uses static java.


Can an abstract method be declared static in java?

No you cant, any compiler I've ever used wont allow this. It would not make any sense to do this anyway. because the JVM directly accesses ur top class without instantiating it. Though for accessing the instance data members, the class must need to be instantiated.

Related questions

Are static variable created by giving keyword static in java?

yes bcoz static variables


Is it possible to write in static variables in main method in java?

Short answer: No. Only class member variables may be declared static. Local variables with a static declaration will throw an error (usually "illegal start of expression").


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


How do you access the static variable and static methods of a class?

In java we access static variables and static methods without creating objects. i.e.,we can access directly by using classname we can also access static variables and static methods by using objects which are created by using class where the static variables and static methods are available


Can transient variables be declared as 'final' or 'static'?

Transient Variables are those that do not get serialized during the Serialization process. A Static variable is one that is mapped to the Class and is not mapped to any object instance and hence they would not get serialized. So, there should be no problem with declaring a transient variable as static. On the other hand, A final variable is one that's value cannot change. So if you declare a final variable as transient, it would get stored as null during serialization and when you try to de-serialize the variable, you will get errors because, the variable is final and you cannot assign values for it and it is saved as null during serialization. Result: Yes you can have static transient variables but not final transient variables.


What is Static method in programming?

A static method in java is also named a class method, because it does not need an instance (of his class) to be invoked. Static methods can't use instance variables (non static variables) or use the keywords 'this'. These methods receive all the information they need to complete his task from his parameters


Which one executed first static block or static methods in java?

Static Blocks are always executed first. A static block is executed when your class is charged but a static method is executed only when is called, therefor first the class is charged and then is executed a method.


Static membors partispating Overwriting in java?

Static membors partispating in Overwriting in java?


What is static java most commonly used for?

Static java method is the same as a static variable. They belong to a class and not an object of that class. If a method needs to be in a class, but not tied to an object, then one uses static java.


Why static functions cannot use instant variables?

Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.


Can an abstract method be declared static in java?

No you cant, any compiler I've ever used wont allow this. It would not make any sense to do this anyway. because the JVM directly accesses ur top class without instantiating it. Though for accessing the instance data members, the class must need to be instantiated.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.