what is the Difference between ? new Operator and Class.forName() ?

plz tel me ....what is the Difference between ? new Operator and Class.forName() ? ........
[105 byte] By [sumit.manhasa] at [2007-10-3 11:44:38]
# 1
The new operator returns an instance of a class.Class.forName looks up a class for a given name.So they're really entirely different things. One gives you an object, and the other gives you a class.
paulcwa at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 2
@Op. Why do you ask? What do you want to do?
kajbja at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 3

Class.forName(), takes the class name as parameter, and loads that class in memory. But it doesn't create any instance of that class.

That means static methods/variables are available for use.

new keyword, checks if the class is loaded, if not then loads that class, and then creates an instance of that class.

Sumit_Tyagia at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 4
> @Op. Why do you ask? What do you want to do?Leech knowledge without reading the specs.
CeciNEstPasUnProgrammeura at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 5
> > @Op. Why do you ask? What do you want to do?> > Leech knowledge without reading the specs.Sounds odd to come up with a question like that. I think I saw the exact same question just a week ago.
kajbja at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks Sumit ......
sumit.manhasa at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks sumit i have given u the dukes
sumit.manhasa at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 8
I am glad, my answer satisfied you.
Sumit_Tyagia at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 9
> I am glad, my answer satisfied you.It doesn't satisfy me. Is it really new that loads a class, or is it the JVM that loads it once anything of that class is used somewhere? And does forName() always load the class?:)
CeciNEstPasUnProgrammeura at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 10

> Class.forName(), takes the class name as parameter,

> and loads that class in memory. But it doesn't create

> any instance of that class.

> That means static methods/variables are available for

> use.

>

> new keyword, checks if the class is loaded, if not

> then loads that class, and then creates an instance

> of that class.

Class.forName actually returns the class object for that name (class - for -name). it might load it, if the class hasn't already been loaded, but it's misleading to say that's what that method does

your definition of 'new' is wrong, too. give the dukes back

georgemca at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 11
> your definition of 'new' is wrong, too. give the> dukes back:) I think this is a nice example "correct is what I want to hear".
CeciNEstPasUnProgrammeura at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 12
'cmon guys,,the "Duke" has already been awarded... :)this thread is closed.
angeles1016a at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 13
> this thread is closed.It's not. I can still post here. Plus, it might be advisable to point out the insufficiency/incorrectness of the answer, lest someone else reads it. It has nothing to do with dukes, even in an un-duked thread, Sumit's statement would have been
CeciNEstPasUnProgrammeura at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 14

> > your definition of 'new' is wrong, too. give the

> > dukes back

>

> :) I think this is a nice example "correct is what I

> want to hear".

I have an inkling - but I'm far from sure - that they're the same person, bumping their dukes score up

georgemca at 2007-7-15 14:16:48 > top of Java-index,Java Essentials,Java Programming...
# 15

>I have an inkling - but I'm far from sure - that they're the same person, bumping their dukes score up

This is the forum where I learnt a lot!!! I can't cheat with it.

If you think so, then I am returning back my duke dollers in an empty post.

I will award it to you, you just reply to that post.

and I answered what I knew, and I thank you all for updating my knowledge.

But please correct my answer about new keyword.

Sumit_Tyagia at 2007-7-21 14:02:36 > top of Java-index,Java Essentials,Java Programming...
# 16

I have no interest in duke dollars. give 'em back to the OP. you're probably not the same person

new doesn't have anything to do with loading classes, it just asks the JVM for a new instance of a class. if the JVM needs to load that class, it does so. but really, the difference between 'new' and Class.forName is that they are entirely different mechanisms in the language, like Object.equals and interfaces

georgemca at 2007-7-21 14:02:36 > top of Java-index,Java Essentials,Java Programming...