Search code examples
javadata-storage

A good way to store data of a person in Java?


I would like to store some data such as first name, last name, date of birth, address, telephone number, etc. There will probably be about 50 fields in total. What would be a good way to store that data? I was thinking of just using a class named Person and put bunch of members in it for the fields. Ex:

public class Person {
    private String fName;
    private String mName;
    private String lName;
    private String dob;
    private String address;
    private String phNumber;
    private String sex;
    private String aka;
    // etc...
    public void setfName(String st) {
        fName = st;
    }
    public String getfName() {
        return fName;
    }
    // etc....
}

Is there a better way to perform this task?

EDIT:

I should also mention that each of the data fields will be (hopefully if I figure out how to do it) inserted into a Microsoft Word template. I'm not necessarily planning on working with the data beyond that scope. What I have at this moment is a pdf document, which I was able to extract text from. I will parse that text and attempt to get all the data out of it. I will then insert that data into the word template (if it's possible).


Solution

  • It depends on what your needs are.

    Using a String for every piece of information is probably a bad idea. You should use appropriate data types for the information you're storing.

    • A Calendar instance for date of birth
    • An enum for gender
    • A custom class for addresses which has fields for house number, street, unit number, city, state, zip code, etc.