Skip to main content

JavaFx : Is there difference between String and StringProperty in Model Classes? [Resolved]

I'm trying to follow MVC concepts when i develop my application ,but I'm confused between Using String or StringProperty in Model classes.

Example one :

public class User{

    String name;
    String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

Example Two:

public class User{

    StringProperty name;
    StringProperty password ;

    public StringProperty getName() {
        return name;
    }

    public void setName(StringProperty name) {
        this.name = name;
    }

    public StringProperty getPassword() {
        return password;
    }

    public void setPassword(StringProperty password) {
        this.password = password;
    }

    public User(StringProperty name, StringProperty password) {
        this.name = name;
        this.password = password;
    }

I'm using example one ,Is there difference between these models or are they the same ?


Question Credit: Xlint Xms
Question Reference
Asked June 12, 2019
Posted Under: Programming
54 views
2 Answers

One difference that should be noted is JavaFX properties are not Serializable. See @jewelsea answer here.


credit: Sedrick
Answered June 12, 2019
Your Answer