
// ...
}
Creating Objects
Every object in Java is allocated on the heap. To create objects in Java, you
use the new operator.
1. The following example creates a
BufferedReader object:
BufferedReader reader =
new BufferedReader(new FileReader(args[0]));
2. Objects are typically assigned to variables, but they need not be. It is
also very common to create anonymous objects that are used and dis-
carded in one sequence. The following example creates a
File object,
calls its exists() method, and then discards it. The object is immedi-
ately discarded because it is never assigned to a variable:
if(new File(args[1]).exists())
System.err.println(“Error: output ...