title: Java Convention of Getter&Setter
body: <p>I got a question about the Java convention of using Getter &amp; Setter.</p>
  
  <p>By now I have a basic understanding of how Java works and I've written a Flappy-Bird and several other tools myself.</p>
  
  <p>What I still dont understand is: Why to use Getter &amp; Setter?</p>
  
  <p>I mean: If I have a variable x and set that variable public, then everyone else working at the project can access it.
  If I want to prevent that, then okay, i set it private and write a public Getter-method to allow others get the variable(but not modify it).</p>
  
  <p>But if I now also write a public Setter-method, then everyone can use that Setter-method to modify the variable.</p>
  
  <p>Overall I just see any sense when I only want others to read(get) my variable, but if they should also be able to modify(set) it, why not just make the variable public?</p>
  
  <p>Edit: I've read about one advantage being that I can easily add one line of code in the Setter instead of in every usage of the public variable, if my Setter is supposed to do more than setting the variable, but wouldn't that again be considered as bad style?</p>