Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Java Swing serializable?

When I create Swing apps for remote users, I just create jar files and create a WebStart file to let users download the app and then run it. I haven't heard of application servers serving up JFrames, etc, like JSPs. Was that the original intent?

like image 430
Gary Kephart Avatar asked Jan 13 '09 22:01

Gary Kephart


People also ask

Why do we go for serialization in Java?

Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage. Deserialization is the process of converting Object stream to actual Java Object to be used in our program.

Why is serializable?

Serialization is simply turning an existing object into a byte array. This byte array represents the class of the object, the version of the object, and the internal state of the object. This byte array can then be used between JVM's running the same code to transmit/read the object.

What is serializable in spring boot?

Serializable is one of the few marker interfaces found in core Java. Marker interfaces are special case interfaces with no methods or constants. Object serialization is the process of converting Java objects into byte streams. We can then transfer these byte streams over the wire or store them in persistent memory.

What does serializable interface do in Java?

Serializable is a marker interface (has no data member and method). It is used to "mark" Java classes so that the objects of these classes may get a certain capability. The Cloneable and Remote are also marker interfaces. The Serializable interface must be implemented by the class whose object needs to be persisted.


2 Answers

Persistence.

If you want to have nothing other than the UI you could persist it to disk and then restore it the next time the program is run.

It'd come back up with everything exactly as you left it.

No fancy stuff required.

like image 91
Allain Lalonde Avatar answered Sep 17 '22 15:09

Allain Lalonde


I've actually used it in the past. Build a compiler that takes in XML data, configures and builds your display objects up, serialize them and then pass them on to a thin client that doesn't know anything beyond UI and simple callbacks.

Of course it turned out to be terribly inefficient. We wound up seperating the data into a different class and using an instance of that as a parameter for our display object constructors.

There's no good reason I can think of to have the swing objects themselves serializable, except for ease of use. In fact it turned out to be a little dangerous, since we thought "if they made it serializable in the first place, then it can't be that bad an idea."

like image 45
patros Avatar answered Sep 17 '22 15:09

patros