This article describes transient Keyword in Java.
The transient
keyword in Java is used to indicate that a field should not be serialized. When an object is serialized, the values of its transient fields are not included in the serialization process. This can be useful if a field is not important or if its value can be recalculated later.
Example of transient Keyword in Java
import java.io.Serializable;
class User implements Serializable {
private String username;
private transient String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
In the example, the password
field is marked as transient
, which means that its value will not be serialized (i.e., saved) when the User
object is persisted.
Further Reading
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
![programmingempire](https://www.programmingempire.com/wp-content/uploads/2021/10/pefavicon.png)