Class instance creation expressions

The following article is meant to be a more easily understood version of the Java Language Specification (JLS) section 15.9 on class instance creation expressions. In order to match the flow of this article to the actual JLS the same order of explanations and format will be used. Text taken directly from the JLS will appear in the way the following sentence does.
This text is from the JLS.

Lets start with a few basics:
A simple name of a class is just the one word name of the class, not the full class name. For example the class java.lang.Object can be referred to by its simple name of Object. A non final class is a class whose declaration does not contain the keyword final. The following is a final class declaration:

public final class Test
{
}
What exactly is a class instance creation expression? Basically it is any expression who's desired result is the creation of a new instance of a class. They can appear in one of two main forms, qualified or unqualified.

An unqualified expression has the form:
new ClassOrInterfaceType ( ArgumentListopt ) ClassBodyopt
The keyword new is, of course, the key word new. The ClassOrInterfaceType is the type of the class being created. If, for example, you have a class named MyClass,an unqualified creation expression for an instance of this class would look like:

new MyClass( );
You can use an unqualified expression to create any type of class instance you desire.

A qualified expression looks like this:
Primary.new Identifier ( ArgumentListopt ) ClassBodyopt
Qualified expression are used to create instances of inner classes. The Primary part of the expression identifies the outer (enclosing) class. new is, again, the new keyword. Identifier is the simple name of the inner class being created. As an example, assume you have a class named Outer that has an inner class named Inner. The expression to create an instance of inner would look like:

new Outer( ).new Inner( );
A qualified expression is used to create an instance of an inner class when there is no enclosing class instance present.

In both type of expressions the argument list is an option list of values passed tot he constructor that is called when the instance is created. Both types can also have an optional class body following the creation expression, if there is a class body then the creation expression is for an anonymous class. In all cases the type of the class being created must be accessible, see the JLS section 6.6.

Ok, all of that is great but what exactly does instantiated mean? Instantiated is simply when an instance of a class is created through a class instance creation expression. Want more detail? Ok, there are four basic steps that go into the creation of a class instance:

  1. determine what class is being created
  2. what are the enclosing instances (there might not be any)
  3. what constructor is going to be used
  4. what arguments get passed to the constructor
Finding out what class is being created

The two type of creation expression can be divided into two main groups – with and without a class body. As mentioned, if a class body follows the expression then an anonymous class is being created.

If the expression is unqualified then you are creating either an anonymous direct subclass of the class named in the ClassOrInterfaceType or an anonymous direct subclass of Object that implements the interface named.

In a qualified expression then you are creating an anonymous direct subclass of the class named in the Identifier. The class is an inner class that is a member of the class specified as the Primary.

In both cases the class being subclassed must be non-final and accessible.

If the expression is not for anonymous class then an unqualified expression creates an instance of the class named in the ClassOrInterfaceType. And a qualified expression creates a class of the type identified by Identifier. The type named by the Identifier must be an inner class of the class named in Primary. In either case the class being created must not be abstract, it must be accessible, and for inner classes the Identifier must be a simple name of the class.

Determine the enclosing instances

This only applies to inner classes (non-static member classes). If you are creating an instance of an inner class then that instance is associated with an instance of the enclosing class. This is called the enclosing instance. There are several steps to determine what the enclosing instances are.

If the class being created is an anonymous class:

If the class being created is a local class (it is declared inside of a method inside of another class): If the class being created is not an anonymous class and it's not a local class then it is just a plain old regular member class – a nested class not declared static and not defined in a method.