How to instantiate a class in Java?

To instantiate a class in Java, use the new keyword like so: new MyClass().

So, if your class looks something like this:

public class Person {

}

Then you can create an instance of it like this:

Person person = new Person();

What about constructor arguments?

If your class has constructor arguments:

public class Person {

  private String firstName;
  private String lastName;

  public Person(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
}

Then you can pass these arguments like so:

Person person = new Person("Jane", "Smith");