Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDinu Comendant
6,049 PointsAny examples when we won't use "new"?
I don't feel like I fully understand the "new" concept, are there any examples when you don't use it?
2 Answers
Sean M
7,344 PointsYou use the word "new" for when introducing a new type of object.
For example, when introducing an array list. The code below is implemented.
ArrayList<String> nums = new ArrayList<String>();
Chris Shearon
Courses Plus Student 17,330 PointsYou won't use the "new" keyword for the primitive datatypes.
I may be getting too deep in the Java weeds here but the "new" keyword basically means "Hey JVM, allocate some space on the managed heap and structure it to hold an implementation (or instance) of the <insert object name>.class and return the address (or reference) to that space into the variable <insert variable name>."