Java – What is transient fields?
In Java, transient fields are excluded in the serialization process. In short, when we save an object into a file (serialization), all transient fields are ignored.
Java – How to generate serialVersionUID
This article shows you a few ways to generate the serialVersionUID for serialization class. JDK has a built-in command serialver to generate a serialVersionUID automatically. For Eclipse IDE, move the…
Java – What is serialVersionUID
In Java, serialVersionUID is something like version control, assure both serialized and deserialized objects are using the compatible class. For example, if an object saved into a file (Serialization) with…
Java Serialization and Deserialization Examples
In Java, Serialization means converting Java objects into a byte stream; Deserialization means converting the serialized object’s byte stream back to the original Java object. In Java, we have to…
How to read an object from file in Java (ObjectInputStream)
This example shows how to use ObjectInputStream to read a serialized object from a file in Java, aka Deserialization. The below example converts a Person object to bytes stream and…
How to write an object to file in Java (ObjectOutputStream)
This example shows how to use ObjectOutputStream to write objects to a file in Java, aka Serialization. We can serialize or marshal an object which implements a Serializable interface. We…
How to get free disk space in Java
In Java old days, it lacks of method to determine the free disk space on a partition. But this is changed since JDK 1.6 released, a few new methods –…
Java – Convert File to Hex
This article shows how to convert a file into a hexadecimal (hex) representative format. The idea is to read the file into an InputStream and uses String.format(%X) to convert each…
Java – How to save byte[] to a file
This article shows a few ways to save a byte into a file. For JDK 1.7 and above, the NIO Files.write is the simplest solution to save byte to a…
Java – How to convert File to byte[]
In Java, we can use Files.readAllBytes(path) to convert a File object into a byte. Before Java 7, we can initiate a new byte with a predefined size (same with the…