חוֹלֵף הוא משנה משתנים המשמש ב סדרה . בזמן הסידרה אם אנחנו לא רוצים לשמור ערך של משתנה מסוים בקובץ אז אנחנו משתמשים חוֹלֵף מילת מפתח. כאשר JVM נתקל חוֹלֵף מילת המפתח היא מתעלמת מהערך המקורי של המשתנה ושמירת ערך ברירת המחדל של סוג הנתונים המשתנה הזה. חוֹלֵף מילת מפתח ממלאת תפקיד חשוב כדי לעמוד באילוצי האבטחה. ישנן דוגמאות שונות מהחיים האמיתיים שבהם אנחנו לא רוצים לשמור נתונים פרטיים בקובץ. שימוש נוסף ב חוֹלֵף מילת המפתח היא לא לעשות בסידרה את המשתנה שאת ערכו ניתן לחשב/לגזור באמצעות אובייקטים מסודרים אחרים או מערכת כגון גיל של אדם תאריך נוכחי וכו'. למעשה, הצגנו בסידרה רק את השדות המייצגים מצב של מופע לאחר שכל הסדרה עומדת לשמור מצב של אובייקט בקובץ. זה הרגל טוב להשתמש חוֹלֵף keyword with private confidential fields of a class during serialization. Java // A sample class that uses transient keyword to // skip their serialization. class Test implements Serializable { // Making password transient for security private transient String password; // Making age transient as age is auto- // computable from DOB and current date. transient int age; // serialize other fields private String username email; Date dob; // other code } חולף וסטטי: מֵאָז סטָטִי שדות אינם חלק מהמצב של האובייקט אין שימוש/השפעה של השימוש חוֹלֵף מילת מפתח עם משתנים סטטיים. עם זאת אין שגיאת קומפילציה. חולף וסופי: משתנים סופיים מסודרים באופן ישיר לפי הערכים שלהם, כך שאין שום שימוש/השפעה של הכרזת המשתנה הסופי בתור חוֹלֵף . There is no compile-time error though. Java // Java program to demonstrate transient keyword // Filename Test.java import java.io.*; class Test implements Serializable { // Normal variables int i = 10 j = 20; // Transient variables transient int k = 30; // Use of transient has no impact here transient static int l = 40; transient final int m = 50; public static void main(String[] args) throws Exception { Test input = new Test(); // serialization FileOutputStream fos = new FileOutputStream('abc.txt'); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(input); // de-serialization FileInputStream fis = new FileInputStream('abc.txt'); ObjectInputStream ois = new ObjectInputStream(fis); Test output = (Test)ois.readObject(); System.out.println('i = ' + output.i); System.out.println('j = ' + output.j); System.out.println('k = ' + output.k); System.out.println('l = ' + output.l); System.out.println('m = ' + output.m); } } Output : i = 10 j = 20 k = 0 l = 40 m = 50