Generate serialVersionUID in Java (Eclipse, IntelliJ)

In this short post, I will be sharing how to generate serialVersionUID in eclipse ide, IntelliJ IDEA, and using the built-in JDK command for serialization class in Java. Let's dive deep into the topic:
1. Using Eclipse IDE
2. Using IntelliJ IDEA
3. Using built-in JDK command
4. Using 1L

Read Also : What is serialVersionUID

1. Using Eclipse IDE

In Eclipse IDE, move the mouse over the class name implementing the Serializable interface, or click on the Serialization class and press CTRL + 1.
generating serialVersionUID in eclipse in Java

2. Using IntelliJ IDEA

In IntelliJ Idea, we have to manually enable the auto-generate serialVersionUID option. You can find the detailed explanation here.

3. Using built-in JDK command

JDK provides the built-in command to generate a serialVersionUID automatically. The command is serialVer.

Syntax



serialVer className

In the below example we are generating the serialVersionUID of the HelloWorld class. Make sure the HelloWorld class is implementing the Serializable interface.
generate serialVersionUID using serialVer

4. Using 1L

Last but not the least, you can use the serialVersionUID=1L. It will be enough for most of the cases.

Syntax



private static final long serialVersionUID = 1L;


That's all for today, please mention in the comments in case you have any questions related to how to generate serialVersionUID in Java.

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry