Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new Operator purpose

 
Mohammed Javeed Basha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of new operator in java rather than creating objects?
 
Campbell Ritchie
Sheriff
Posts: 48415
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you meant other than creating objects? Has it got another purpose? I thought that was it.
If you go through the Java™ Language Specification (JLS) contents with ctrl-f-new, this is the only “hit”. Have a look at it. In chapter 18 of the JLS, the word new only seems to appear thrice. Have a look at that, too.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "new" operator allocates memory (on the heap) for a new object and initializes the new object.
 
Mohammed Javeed Basha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for my english yes other than only, other than creating and allocating memory for objects
 
Campbell Ritchie
Sheriff
Posts: 48415
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, I thought that was its only use. If you look for “new” as I said earlier, there do not appear to be any other uses for it.
 
Mohammed Javeed Basha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all who replied
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic