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 13, 2018 in Java by misc.edu04
• 1,450 points

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 13, 2018 by code.reaper12
• 3,500 points

Related Questions In Java

+1 vote
2 answers

Retrieve all the implementations of an interface in Java

Take a look to this example: ...READ MORE

answered Dec 21, 2019 in Java by Roberto
• 460 points

edited Jul 7, 2020 by Roberto 36,958 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
• 59,230 points
0 votes
1 answer

what is functional interface in java?

A functional interface in Java is an ...READ MORE

answered Oct 17, 2023 in Java by anonymous
• 520 points
+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,220 points
0 votes
1 answer

What is the use of serialVersionUID ?

The docs for are probably about as good ...READ MORE

answered Jun 21, 2018 in Java by Rishabh
• 3,620 points
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,620 points
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,320 points
+5 votes
4 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,450 points

edited Nov 7, 2018 by Omkar 79,868 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,500 points
0 votes
1 answer

Need for finalize() in Java

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

answered May 9, 2018 in Java by code.reaper12
• 3,500 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP