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,380 points
90 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,450 points

Related Questions In Java

0 votes
1 answer

Retrieve all the implementations of an interface in Java

Hi...I think you can achieve this by ...READ MORE

answered Jul 23, 2018 in Java by anto.trigg4
• 3,420 points
524 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 in Java by Sirajul
• 25,180 points
65 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
315 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 in Java by Sirajul
• 25,180 points
131 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,540 points
85 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,540 points
2,091 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 in Java by developer_1
• 3,300 points
29 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,380 points

edited Nov 6, 2018 by Omkar 7,993 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,450 points
87 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,450 points
72 views