473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

creating java objects at runtime

184 100+
Hi all,
only during runtime , i know the class for which i need to create the object.How to generate objects for different classes at run time??
Please do needfull..


-Hamsa
Oct 10 '07 #1
6 2723
dmjpro
2,476 2GB
Hi all,
only during runtime , i know the class for which i need to create the object.How to generate objects for different classes at run time??
Please do needfull..


-Hamsa
Have a look "Class" class in Java.

Debasis Jana
Oct 10 '07 #2
gaya3
184 100+
Have a look "Class" class in Java.

Debasis Jana

Hi dmjpro....
Thank u....I tried with following
Class CN = Class.forName("ClassName");
Object o = CN.newInstance();
For that i m getting InstantiationException...How to resolve??

-Hamsa
Oct 10 '07 #3
dmjpro
2,476 2GB
Hi dmjpro....
Thank u....I tried with following
Class CN = Class.forName("ClassName");
Object o = CN.newInstance();
For that i m getting InstantiationException...How to resolve??

-Hamsa
May be you have no default "Constructor" or you have that "Constructor" as "private" or "protected"
Have a through look at the "API".
Actually "Why this Exception thrown" !
Also having look at "Constructor" and "Method" classes.
This will help you to resolve that problem with that particular "class".

Debasis Jana
Oct 10 '07 #4
r035198x
13,262 8TB
Hi all,
only during runtime , i know the class for which i need to create the object.How to generate objects for different classes at run time??
Please do needfull..


-Hamsa
Expand|Select|Wrap|Line Numbers
  1. ClassName object = new ClassName();
creates an object from a class called ClassName.
Oct 10 '07 #5
gaya3
184 100+
Have a look "Class" class in Java.

Debasis Jana

Hi dmjpro,
Thank u...
could u please clear me following doubt...

Class c1 = Class.forName("x1.x2.x3.service.DropdownService");
when i print "c1" its printing as
" interface x1.x2.x3.service.DropdownService"

but i need "class" for that DropdownService... what to do??
please do needfull...


-Hamsa
Oct 10 '07 #6
dmjpro
2,476 2GB
Hi dmjpro,
Thank u...
could u please clear me following doubt...

Class c1 = Class.forName("x1.x2.x3.service.DropdownService");
when i print "c1" its printing as
" interface x1.x2.x3.service.DropdownService"

but i need "class" for that DropdownService... what to do??
please do needfull...


-Hamsa
You want the implemented Classes?

Debasis Jana
Oct 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
8
by: Steven T. Hatton | last post by:
I've had an idea kicking around in my head regarding how to create a library of classes (templates?) that provide the same kind of functionality as do Java classes which all derive from the UBC...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
2
by: Krzysztof Paz | last post by:
Hi, There is a Java (SUN 1.4) server which using Object Input/Output Streams at SSL/Socket to communicate with Java clients. Now there is a request for making C# Client for this server also. SSL...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.