Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:45:20+00:00 2026-05-24T08:45:20+00:00

public class Employee implements java.io.Serializable { public String name; public int transient id; }

  • 0
public class Employee implements java.io.Serializable
{
 public String name;
 public int transient id;
}

Suppose we are serializing …

Employee e = new Employee();
e.name="REUBEN";
e.id=94731;

Now if I deserialize this then

System.out.println("Name: " + e.name); will give the o/p REUBEN
System.out.println("ID: " + e.id); will give the o/p 0

It is clear that as id is transient it was not sent to the output stream.

My question is, this zero is the default value of int ?
We are not saving the state so it is giving the output as 0 , but it is also a value. Shouldn’t it be null ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:45:20+00:00Added an answer on May 24, 2026 at 8:45 am

    Yes, member variables of a class get their default values when they come into being (when they are created in a a JVM) hence the 0, which is the default value of the primitive int type. If this is causing problems with “verifying” whether the ID was sent across or not, just use Integer which would get the default value of null (not that it should be a source of any confusion, just saying).

    public class Employee implements java.io.Serializable
    {
     public String name;
     public transient Integer id;
    }
    System.out.println("Name: " + e.name); will give the o/p REUBEN
    System.out.println("ID: " + e.id); will give the o/p null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
I have a table bean as : public class Employee implements Serializable { @Id
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have an entity like: public class Employee { public int ID { get;
I have @manytomany relation in hibernate Like : Table Employee public class Employee implements
class Employee { private String name; void setName(String n) { name = n; }
I have the following requirement I have a Employee class: public class Employee {
This is what my data model classes look like: public class Employee { public
As a simplified example, I have the following data classes: public class Employee {
I have two classes Address and Employee as follows: public class Address { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.