In Java, how can you declare a variable non-serializable?

In Java, how can you declare a variable non-serializable? When it is required?

Ninja Asked on 17th September 2018 in Java.
Add Comment
1 Answer(s)
Best answer

A variable can be made non-serializable by declaring it as transient by using ‘transient’ keyword. By default all variables are persistent.
Variables can be marked ‘transient’ when you want to avoid persisting them, you don’t have the necessity to maintain their state.

Ninja Answered on 17th September 2018.
Add Comment