title: Calling multiple methods in Java
body: <p>I found a new way of calling multiple methods in Java and I don't really understands what's happening behind:</p>
  
  <pre><code>public class NutritionFacts {
  private final int servingSize;
  private final int servings;
  private final int calories;
  private final int fat;
  private final int sodium;
  private final int carbohydrate;
  
  public static class Builder {
      // Required parameters
      private final int servingSize;
      private final int servings;
      // Optional parameters - initialized to default values
      private int calories      = 0;
      private int fat           = 0;
      private int carbohydrate  = 0;
      private int sodium        = 0;
      public Builder(int servingSize, int servings) {
          this.servingSize = servingSize;
          this.servings    = servings;
      }
          public Builder calories(int val)
              { calories = val;      return this; }
          public Builder fat(int val)
              { fat = val;           return this; }
          public Builder carbohydrate(int val)
              { carbohydrate = val;  return this; }
          public Builder sodium(int val)
              { sodium = val;        return this; }
          public NutritionFacts build() {
              return new NutritionFacts(this);
          }
  }  
  
      private NutritionFacts(Builder builder) {
          servingSize  = builder.servingSize;
          servings     = builder.servings;
          calories     = builder.calories;
      }
  
  }
  </code></pre>
  
  <p>Now the class is instantiated using this line, and here's where it gets confusing:</p>
  
  <pre><code>NutritionFacts cocaCola = new NutritionFacts.Builder(240, 8).calories(100).sodium(35).carbohydrate(27).build();
  </code></pre>
  
  <p>It all makes sense till the NutritionFacts.Build(int, int), after that, what exactly is happening? Why do the <code>calories</code>, <code>sodium</code>, <code>carbohydrate</code> methods from Builder class need to return <code>this</code>? Where does that class adress go into?</p>
  
  <p>Thank you!</p>