The first tries to create an instance of WindowAdapter, we kmow it will fail, because WindowAdapter is an abstract class.
The second is doing a different thing. It creates a new anonymous class which extends WindowAdapter and the implementation is in the {...}
If you do not implement all abstract methods in the WindowAdapter, you still receive a compiler error.
Java supports anonymous class for programmers convenience. In this case, you do not have to write a small class in its own .java file and you do not care its name.
Anonymous class also support interfaces with the same syntax:
You have:
abstract class ClassA
interface InterfaceA
Then you can write code like:
new ClassA() { implementation }
new InterfaceA() { implementation }
In a compiler's eye, they are exactly the same as:
class Class$1 extends ClassA {implementation}
new Class$1(..)
class Class$2 implements InterfaceA {implementation}