Serializable interface in Java

0 votes

Since Serializable is an empty interface which makes Java robust when it is implemented, why it's not implemented to all the classes by default?

Please explain.

Jun 12, 2018 in Java by misc.edu04
• 1,430 points
151 views

1 answer to this question.

0 votes

Serializable is a marker interface that has no data member and method. It is used to mark java classes to provide them with certain capabilities. If automatic serialization support is provided it will make the class internal a part of public API. This restricts from making any changes to class design which breaks encapsulation. Moreover, serialization sometimes can also lead to many security issues such as now any class can access data which normally it can’t. Also, the serialized form of an inner class is generally not being well defined.

So, if we make all the classes Serializable, it will only worsen the issue. Hope now you get the reason behind why classes are not Serializable by default.

answered Jun 12, 2018 by code.reaper12
• 3,470 points

Related Questions In Java

+1 vote
2 answers

Retrieve all the implementations of an interface in Java

Take a look to this example: https://github.com/burningwave/cor ...READ MORE

answered Dec 20, 2019 in Java by Roberto
• 370 points

edited Apr 10 by Roberto 5,719 views
0 votes
2 answers

Why it is not possible to define a static method in a Java interface?

Interfaces are concerned with polymorphism which is ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 52,710 points
214 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
1,600 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 52,710 points
383 views
0 votes
1 answer

What is the use of serialVersionUID ?

The docs for java.io.Serializable are probably about as good ...READ MORE

answered Jun 21, 2018 in Java by Rishabh
• 3,580 points
342 views
0 votes
1 answer

How to tell Jackson to ignore a field during serialization if its value is null?

To suppress serializing properties with null values ...READ MORE

answered Jul 4, 2018 in Java by Rishabh
• 3,580 points
3,792 views
0 votes
1 answer

Use annotation for excluding specific fields from serialization

Simply mark the desired fields with the ...READ MORE

answered Feb 1, 2019 in Java by developer_1
• 3,300 points
91 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,400 points

edited Nov 6, 2018 by Omkar 21,105 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,470 points
177 views
0 votes
1 answer

Need for finalize() in Java

finalize() is a method called by the ...READ MORE

answered May 8, 2018 in Java by code.reaper12
• 3,470 points
116 views