Skip to content

Instantly share code, notes, and snippets.

@rajendrauppal
Last active June 2, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajendrauppal/18e3989bf35157ca8045332968bf1b8e to your computer and use it in GitHub Desktop.
Save rajendrauppal/18e3989bf35157ca8045332968bf1b8e to your computer and use it in GitHub Desktop.
Java Bean
import java.io.Serializable;
// 1. Implement Serializable interface
public class User implements Serializable {
// 2. All attributes must be private
private int id;
private String name;
// 3. Should have a no argument public default constructor
public User() {}
public User(int id, String name) {
this.id = id;
this.name = name;
}
// 4. Should have public getters and setters for attributes
public getId() { return this.id; }
public setId(int id) { this.id = id; }
public getName() { return this.name; }
public setName(String name) { this.name = name; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment