It's not a secret anymore!*
The moose likes Java in General and the fly likes Object creation in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object creation in java" Watch "Object creation in java" New topic
Author

Object creation in java

rajaraman navaneethan
Ranch Hand

Joined: Feb 26, 2005
Posts: 86
Hi,
How many objects are created when I run a simple HelloWorld Program shown below.

class HelloWorld
{
public static void main(String args[])
{
System.out.println("HelloWorld");
}
}

Is java.lang.Class instance created for this class?If so, when is it created?
Can anyone please give me a good link which would help me understand java.lang.Class?

regards,
Raja
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

None of the code here explicitly or implicitly creates any objects. But JVM startup creates hundreds, and then loading your class and invoking your application creates more (the java.lang.Class object, of course, and some indeterminate number of subordinate objects, and a String[] to pass as an argument to main() ). This question is really very vague; you have to be more specific as to which objects should be included, and even then, lots of what happens is implementation-specific.

As far as java.lang.Class: the JVM creates a class object in the process of loading a class into the JVM. You can read the Javadocs for java.lang.Class and java.lang.Classloader to get an introduction to these classes; otherwise, the Java VM spec is the place to go for detailed information. See http://java.sun.com/docs/books/jvms/ .

If you have specific questions about these classes, you could ask them here.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object creation in java