File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object creation in java" Watch "Object creation in java" New topic

Object creation in java

rajaraman navaneethan
Ranch Hand

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

class HelloWorld
public static void main(String args[])

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?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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 .

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

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Object creation in java
It's not a secret anymore!