Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Object without using 'new'

This is a discussion on Object without using 'new' within the Java forums, part of the Software Development category; Can we create an object with out using 'new' keyword in java?...

Go Back   Geeks Talk > Software Development > Java
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Java Java related Issues and Problems

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-30-2007
Junior Member
 
Join Date: Nov 2005
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
ani_lavanya is on a distinguished road
Object without using 'new'

Can we create an object with out using 'new' keyword in java?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-01-2007
Junior Member
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
akhilsyal1982 is on a distinguished road
Re: Object without using 'new'

yeah in case of Strings we can create a new object by using the below given statement

String str = "Test_String";

this will create a new String object and the reference variable str will refer to that object. the value of that object will be Test_String
Reply With Quote
The Following User Says Thank You to akhilsyal1982 For This Useful Post:
  #3 (permalink)  
Old 05-03-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 9 Times in 8 Posts
vmshenoy is on a distinguished road
Re: Object without using 'new'

ya this is only possible with strings.

String is a class in Java.
You can create java String object using new.
String str=new String("");
String str="erer";

Both ways create String object.

Hope iam clear
__________________
:)
NEVER SAY DIE.
Reply With Quote
  #4 (permalink)  
Old 05-09-2007
Junior Member
 
Join Date: May 2007
Location: bangalore
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
sathya_raj2 is on a distinguished road
Re: Object without using 'new'

Quote:
Originally Posted by ani_lavanya View Post
Can we create an object with out using 'new' keyword in java?
Yes we can create object without using new
1.clone()
2.newinstance() in java.lang.class
Reply With Quote
  #5 (permalink)  
Old 05-12-2007
Junior Member
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
viquaruddin is on a distinguished road
Re: Object without using 'new'

Quote:
Originally Posted by ani_lavanya View Post
Can we create an object with out using 'new' keyword in java?
Yes, Thats quite possible using the factory methods or using Creational Patterns.
Reply With Quote
  #6 (permalink)  
Old 06-03-2007
Junior Member
 
Join Date: Jun 2007
Location: Hyderabad
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
sudha_kumari7 is on a distinguished road
Re: Object without using 'new'

Hi lavanya we can create object without using new opearator.

1) Using factory methods
Ex:- NumberFormat obj=NumberFormat.getInstance();

2)Using newInstance() method
Ex:-
Class c=Class.forName("SomeClassName");
SomeClassName obj=c.newInstance();

3)using cloning
Ex:- ClassName c1=new ClassName();
ClassName c2=c1.clone();
Reply With Quote
  #7 (permalink)  
Old 06-06-2007
Junior Member
 
Join Date: May 2007
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Gangadhar123 is on a distinguished road
Re: Object without using 'new'

yes,we can create the object in 3 ways without using 'new' keyword

1)by calling clone() which has present in Object super class
2)using factory methods,we can get the same type of the object

Ex:take Calender class which is in java.util package,we will get the object of Calender class in following way

Calender objCal = Calender.getInstance(); here getInstance() is factory method

3)using newInstance() ,we can Create a new instance of the class represented by this Class object

Ex:Class objClass=Class.forName("Driverclass name");//objClass is the Class object for the class with the specified name

Object obj=objClass.newInstance(); and then type cast into our class and use that object

Last edited by Gangadhar123; 06-06-2007 at 01:38 AM.
Reply With Quote
  #8 (permalink)  
Old 06-06-2007
Junior Member
 
Join Date: May 2007
Location: Mysore
Posts: 16
Thanks: 1
Thanked 1 Time in 1 Post
umeshap is on a distinguished road
Re: Object without using 'new'

Yes, without using New keyword u can create objects in Java

Last edited by umeshap; 06-06-2007 at 07:26 AM.
Reply With Quote
Reply

  Geeks Talk > Software Development > Java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Object Spy suji QTP 3 06-19-2009 10:05 AM
how to capture properties of an object niharika38 Rational Robot 1 06-01-2007 09:14 AM
Cannot identify the object Livetek QTP 5 04-30-2007 08:31 AM
QTP- wrong object recognised... nusezak QTP 1 02-14-2007 04:37 AM
Create Object JobHelper Java 2 11-30-2006 01:45 AM


All times are GMT -4. The time now is 04:45 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved