• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

creation of object

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir
without using new ,can we create object or not
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name here. Thanks!
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class.newInstance() should do the same thing.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by laxmidhar:
sir
without using new ,can we create object or not



Why do you ask?
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can define your own static newObj() method....

where you have a static global arr[] and as you call newObj,

you decrement down the arr[] and assign that certain object(of whatever

type you want) that type...

This is how they did it in the "old" days...

so i'm told

Justin
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Justin Fox:
you can define your own static newObj() method....

where you have a static global arr[] and as you call newObj,

you decrement down the arr[] and assign that certain object(of whatever

type you want) that type...

This is how they did it in the "old" days...

so i'm told

Justin



Please excuse my apparent ignorance, but wtf?
Can you please elaborate on whatever it is you are trying to say?
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not in Java. Sometimes it is a little hidden like a factory or singleton pattern implementation, but at the point where an object is created, there is a new there. This is not the case in C++ though, which causes confusion sometimes.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rusty Shackleford:
Not in Java. Sometimes it is a little hidden like a factory or singleton pattern implementation, but at the point where an object is created, there is a new there. This is not the case in C++ though, which causes confusion sometimes.



Find the "new" in Class.newInstance. You'll find it calls a native method, so it is possible. For the average developer, new is the only way.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String s = "Joe";

Heh...I just created an object without using the new keyword.

There are exceptions to every rule. Rules are just coathangers for exceptions.

But I like the new keyword. Don't see why I'd stop using it.

-Cameron
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kameron McKenzie:
String s = "Joe";

Heh...I just created an object without using the new keyword.

There are exceptions to every rule. Rules are just coathangers for exceptions.

But I like the new keyword. Don't see why I'd stop using it.

-Cameron



Did you really? It's entirely possible you didn't create anything but a reference to an existing object.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, that may or may not create a new object. But it's an exception to "for the average developer, new is the only way." Here's another:

That does end up being equivalent to

but in terms of Java source code, it's not using "new". I'm not sure if that counts, depending on what the original poster really wants. I think Dana's question is fairly important here: laxmidhar, why do you ask? We can debate minutae about borderline cases, but without a meaningful context for the question, it doesn't much matter, I think.
[ September 01, 2006: Message edited by: Jim Yingst ]
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ken Blair:

Find the "new" in Class.newInstance.



Class.newInstance
 
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic