title: Use method "getValue()" or get property "value"?
body: <p>I'm a beginner programmer in Java, so this may sound like a simple and rather silly question:</p>
  
  <p><strong>In Java, is it better to use a method to get a property value or just use the property itself?</strong></p>
  
  <p>To see what I mean, look at this example from a page from the <a href="http://docs.oracle.com/javase/tutorial/" rel="nofollow">Oracle Java Tutorials</a> about <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html" rel="nofollow">Lambda Expressions</a>:</p>
  
  <pre><code>processPersons(
      roster,
      p -&gt; p.getGender() == Person.Sex.MALE
          &amp;&amp; p.getAge() &gt;= 18
          &amp;&amp; p.getAge() &lt;= 25,
      p -&gt; p.printPerson()
  );
  </code></pre>
  
  <p>I'm just wondering, what would be the use of evoking <code>p.getGender()</code> and <code>p.getAge()</code> when just using <code>p.gender</code> and <code>p.age</code> should have the right values? They can't have multiple values or anything that could prevent them from just using the properties. (<code>p.printPerson()</code> is fine because it might print out multiple property values.)</p>
  
  <p>I mean, to run the above code, they would need to have a constructor to assign properties <em>and</em> extra methods just to return the property values, like so:</p>
  
  <pre><code>public class Person {
      public String name;
      public int age;
      public String gender;
      public Person(String name, int age, String gender) {
          this.name = name;
          this.age = age;
          this.gender = gender;
          // assign some other properties for "printperson()" to print out
      }
      public String printPerson() {
          return name;    // and maybe return some other values
      }
  
      // need the methods below just to return property values??? are they unnecessary??
      public String getGender() {
          return this.gender;  // can't they use "p.gender" to get this value?
      }
      public int getAge() {
          return this.age;     // can't they use "p.age" to get this value?
      }
  }
  </code></pre>
  
  <p>Some of my reasoning is assumptions from my limited programming knowledge, so <strong>please correct me if I'm wrong</strong>.</p>
  
  <p>Is there something I'm missing, a reason why to use methods to get property values? Or was it just used as a example? Because it would seem much simpler to not have to evoke methods and slow the program down.</p>
  
  <p>Any thoughts are appreciated.</p>