Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object creation in java

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic