In AP Computer Science A, the new keyword creates an instance of a class (an object) by allocating memory for it and calling one of the class's constructors, as in Scanner input = new Scanner(System.in); the variable then stores a reference to that new object.
The new keyword is how Java actually builds an object. Writing Rectangle r; only declares a reference variable, which is like an empty address label. Writing r = new Rectangle(5, 3); is what constructs the object. Java allocates memory for it, runs the matching constructor to initialize its instance variables, and hands back a reference (the object's address) that gets stored in r.
The pattern is always the same: ClassName variableName = new ClassName(arguments);. The part after new is a constructor call, so the arguments you pass must match one of the class's constructors in number, order, and type. If a class has multiple constructors (constructor overloading), the arguments you give new decide which one runs. new Rectangle() runs the no-argument constructor; new Rectangle(5, 3) runs the two-parameter one.
Object instantiation with new shows up the moment AP CSA moves from primitives to objects in Unit 2 (Using Objects), and it comes back when you write your own classes and constructors in Unit 5. Almost every FRQ you write will use new somewhere, whether you're creating a Scanner, building an ArrayList, returning a new object from a method, or filling an array with objects. If you don't understand what new does, the difference between a reference and an object stays fuzzy, and that confusion causes NullPointerExceptions, aliasing mistakes, and wrong answers on MCQs about object behavior.
Keep studying AP Computer Science A Unit 1
Constructor (Units 2 & 5)
Every use of new is a constructor call. new allocates the memory, then the constructor fills in the instance variables. They're two halves of one action, which is why the arguments after new must match a constructor's parameter list exactly.
Reference Variable (Unit 2)
new returns a reference, not the object itself. The variable on the left of the equals sign just stores that address. This is why two variables can point to the same object, and why copying a reference variable does not copy the object.
null (Unit 2)
A reference variable that hasn't been assigned with new (or is set to null) points to nothing. Calling a method on it throws a NullPointerException. new is exactly what moves a reference from null to a real object.
Constructor Overloading (Unit 5)
When a class has several constructors, the argument list you pass to new picks which one runs. new Rectangle() and new Rectangle(5, 3) create the same type of object but initialize it through different constructors.
Multiple-choice questions love to test whether you can correctly instantiate an object, like picking the right statement to create a Scanner that reads from the keyboard (Scanner input = new Scanner(System.in);) or choosing which new Rectangle(...) call matches a given constructor in a class with overloaded constructors. Watch for trap answers that skip new, pass arguments in the wrong order, or use a parameter list no constructor accepts. On the free-response section, you'll use new constantly: instantiating objects inside methods, creating and returning new objects, and building ArrayLists with new ArrayList<Type>(). Forgetting new, or calling methods on a reference that was never assigned an object, costs points.
Declaring a variable (Rectangle r;) and creating an object (r = new Rectangle();) are two different steps. Declaration just makes a name that can hold a reference; until you assign it with new, it doesn't point to any object, and calling a method on it throws a NullPointerException. Only new actually constructs the object in memory.
The new keyword creates an object by allocating memory for it and running one of the class's constructors.
Declaring a reference variable does not create an object; only new does, and the variable stores a reference (address) to the object, not the object itself.
The arguments you pass after new must match a constructor's parameters in number, order, and type, and with overloaded constructors those arguments decide which constructor runs.
Calling a method on a reference that was never assigned with new (or that is null) throws a NullPointerException.
The standard pattern to memorize is ClassName name = new ClassName(arguments); and you'll write it in nearly every FRQ.
It creates an object. new allocates memory for an instance of a class, calls a constructor to initialize its instance variables, and returns a reference to the object, as in Scanner input = new Scanner(System.in);.
No. Rectangle r; only declares a reference variable that points to nothing yet. The object doesn't exist until you write r = new Rectangle();. Using r before that throws a NullPointerException.
They work together but aren't the same thing. The constructor is the method that initializes the object's instance variables; new is the keyword that allocates the memory and triggers that constructor call. You can't run a constructor in AP CSA code without new.
Java matches the arguments you pass to new against the constructors' parameter lists. With public Rectangle() and public Rectangle(int len, int w), writing new Rectangle(5, 3) runs the two-parameter version and new Rectangle() runs the no-argument one.
Yes, everywhere. Multiple-choice questions ask you to pick the correct instantiation statement, and almost every FRQ requires creating objects with new, like new ArrayList or a new instance of a given class.