title: How to pass object from one class to another class through methods in java
body: <p>Imagine I have a class and many methods inside it.
  And inside these method I am creating objects. Now in many methods I am creating the same method again and again. So I want to stop these free object creation.</p>
  
  <p>So I am using an Utility class where I can create the object and I can pass the object to the particular method.</p>
  
  <p>Now how to pass an object as a parameter and how to use that object in the method?</p>
  
  <p><strong>Sample Code</strong></p>
  
  <pre><code>public ProfileImpl(String profileId) {
      Utilities.dbConnect();
      if (dbClient.contains(profileId)) {
          this.profile = dbClient.find(TOProfile.class, profileId);
      }
  }
  
  @Override
  public void setProfile(TOProfile profile) {
      CouchDbClient dbClient = new CouchDbClient();
      profile.set_rev(dbClient.update(profile).getRev());
      this.profile = profile;
  }
  
  @Override
  public void getProfile(TOProfile profile) {
      CouchDbClient dbClient = new CouchDbClient();
      profile.set_rev(dbClient.update(profile).getRev());
      this.profile = profile;
  }
  </code></pre>
  
  <p>You can see from code above object dbclient is created again and again. </p>
  
  <p><strong>Utility.java</strong></p>
  
  <pre><code>public lass Utilities {
      public static Object dbConnect(Object object) {
          CouchDbClient dbClient = new CouchDbClient();
          return dbClient;
      }
  }
  </code></pre>
  
  <p>Now I want to pass this object and use it.
  I am new to java coding, so thanks for your answers.</p>