What Is The Transient Keyword In Java?
Maybe your like
ExploreEXPLORE THE CATALOGSupercharge your career with 700+ hands-on coursesView All CoursesPythonJavaJavaScriptCReactDockerVue JSRWeb DevDevOpsAWSC#LEARNING TOOLSExplore the industry's most complete learning platformCoursesLevel up your skillsSkill PathsAchieve learning goalsProjectsBuild real-world applicationsMock InterviewsNewAI-Powered interviewsPersonalized PathsGet the right resources for your goalsLEARN TO CODECheck out our beginner friendly courses.PricingFor BusinessResourcesNewsletterCurated insights on AI, Cloud & System DesignBlogFor developers, By developersFree CheatsheetsDownload handy guides for tech topicsAnswersTrusted answers to developer questionsGamesSharpen your skills with daily challengesSearchCoursesLog InJoin for freeWhat is the transient keyword in Java?
The transient keyword in Java is used to avoid serialization. If any object of a data structure is defined as a transient, then it will not be serialized.
Serialization is the process of converting an object into a byte stream.
Code
In the code below, we have created a Member class object with a transient int id and a simple String name. Since the id is transient, it cannot be written in the file, so 0 is stored instead.
import java.io.Serializable; import java.io.*; class HelloWorld { public static class Member implements Serializable{ transient int id; // This will not serialized. String name; // constructor public Member(int i, String k) { this.id = i; this.name = k; } } public static void main(String args[]) throws Exception { Member temp =new Member( 2, "Clausia");//creating object //writing temp object into file FileOutputStream fread=new FileOutputStream("member.txt"); ObjectOutputStream fout=new ObjectOutputStream(fread); fout.writeObject(temp); fout.flush(); fout.close(); fread.close(); System.out.println("Data successfully saved in a file"); // retrieving the data from file. ObjectInputStream fin=new ObjectInputStream(new FileInputStream("member.txt")); Member membr=(Member)fin.readObject(); System.out.println(membr.id+" "+membr.name+" "); fin.close(); } }RunRelevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reservedTag » What Is Transient In Java
-
Java Programming/Keywords/transient - Wikibooks, Open Books For ...
-
Transient Keyword In Java - GeeksforGeeks
-
The Transient Keyword In Java - Baeldung
-
Transient In Java | What, Why And How It Works - Edureka
-
Java Transient Keyword - Javatpoint
-
Why Does Java Have Transient Fields? - Stack Overflow
-
Java Transient이란? - Nesoy Blog
-
What Is Transient Variable In Java? Serialization Example - Java67
-
Java Transient Keyword Example - HowToDoInJava
-
Transient Keyword In Java - W3schools.blog
-
Difference Between Volatile And Transient In Java - Tutorialspoint
-
Transient Keyword In Java - Tutorialspoint
-
Transient Keyword In Java: What Is It & How It Works? | UpGrad Blog
-
[Java] Transient 키워드 의미 - 데이터 엔지니어링