title: How to import a class to a java program using Javac?
body: <p><strong>Introduction</strong></p>
  
  <p>I'm using the terminal and Javac to compile and run my java programs. Individual programs work fine. However, when i want to import a class into my main Java program,I receive errors.</p>
  
  <p><strong>Source Code  - my class (Name.java)</strong></p>
  
  <pre><code>public class Name {
  
  //Fields
  private String firstName;
  private String familyName;
  
  
  //Constructors
  public Name() {
      firstName = "";
      familyName = "";
  }
  
  public Name(String firstName, String familyName) {
      this.firstName = firstName;
      this.familyName = familyName;
  }
  
  
  //Methods
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  public void setFamilyName(String familyName) {
      this.familyName = familyName;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public String getFamilyName() {
      return familyName;
  }
  
  public String getFullName() {
      if (firstName.equals("") &amp;&amp; familyName.equals("")) {
          return "";
      } else {
          return firstName + " " + familyName;
      }
  }
  
  @Override
  public String toString() {
      return "Name:[firstName=" + firstName + ", familyName=" + familyName + "]";
  }
  }
  </code></pre>
  
  <p><strong>Main - NameDemo.java</strong></p>
  
  <pre><code>import Name;
  
  public class NameDemo {
  
  public static void main(String[] args) {
      /* 
       * See below evidence of how arrays can store elements of a custom reference
       * type that you create (Name in this case), as well as both existing
       * reference types (e.g. String) or primitive types (e.g. int), that you have
       * previously worked with.
       */
  
      //declare array to hold four Name objects
      Name[] friends = new Name[4];
  
      //create Name object and assign reference into array
      Name joe = new Name("Joe", "Bloggs");
      friends[0] = joe;
  
      //create Name objects and assign reference directly into array
      friends[1] = new Name("Fred", "Perry");
      friends[2] = new Name("Diti", "Hammond");
      friends[3] = new Name("Bulsar", "Raymond");
  
      //loop through each element
      for(int i = 0; i &lt; friends.length; i++) {
          //use accessor method to output full name of each
          System.out.println(friends[i].getFullName());
      }
  
      //declare boolean used as a flag
      boolean exists = false;
  
      //loop through each Name object using a for-each loop (you will see more on this when we cover ArrayLists)
      for (Name nm : friends) {
          //check family name
          if (nm.getFamilyName().equals("Smith")) {
              exists = true;
          }
      }
  
      //output result of search
      if (exists) {
          System.out.println("There is a person with family name of Smith");
      } else {
          System.out.println("There is not a person with family name of Smith");
      }
  
      //Checking output of toString
      System.out.println("\n" + joe.toString());
  
  }
  
  }
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>Both files are inside the same directory. AS well as this, i've imported the class into the main program source code. I then proceed to try and compile both.</p>
  
  <blockquote>
    <p>import Name;</p>
  </blockquote>
  
  <pre><code>javac Name.java
  javac NameDemo.java
  NameDemo.java:4: error: '.' expected
  import Name;
             ^
  NameDemo.java:4: error: ';' expected
  import Name;
              ^
  2 errors
  </code></pre>
  
  <p>Why is this occurring, am i supposed to compile the class? or does the class need to end in .class or .java? as well as this is this a syntax issue with the import? </p>