The Java transient keyword is used on class attributes/variables to indicate that serialization process of such class should ignore such variables while creating a persistent byte stream for any instance of that class.
The transient
keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process. In this example, the thumbnailImage
is a thumbnail image that is generated by invoking the generateThumbnail
method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class GalleryImage implements Serializable { private Image image; private transient Image thumbnailImage; private void generateThumbnail() { // Generate thumbnail. } private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException { inputStream.defaultReadObject(); generateThumbnail(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.