• Post Reply Bookmark Topic Watch Topic
  • New Topic

is memory crated at the time of static call?  RSS feed

 
nikunj jhala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i know public static void method() is called because it 's an entry point for compiler.
1) compiler uses the name of class inside which main method is present,
& compiler will call main method with class name.it's fine.( ClassName.main())

but till that time Obect of Class or Reference of that class is not created in memory. so how static method technically call. becz obj is not in memory at the time of execution.how compiler will play with it at runtime.
will it create obj of that class or some thing other ?

how compiler will allocate space & where it will store Static Method & Variable.???

thanks
Nikunj Jhala
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an answer to part of your questions. I believe that the static variables and constants are allocated and initialized when the class is loaded. This may be before any object of that class is being created or initialized.

-- Kaydell
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know public static void method() is called because it 's an entry point for compiler.
1) compiler uses the name of class inside which main method is present,
& compiler will call main method with class name.it's fine.( ClassName.main())


Make sure that you understand the difference between compile time and runtime. Your program does not have an "entry point for the compiler". As far as the compiler is concerned, the method public static void main(String[] args) is just a method like any other method. For the Java runtime environment, the main(...) method is the entry point of your program - that's where the runtime environment starts running your program.

but till that time Obect of Class or Reference of that class is not created in memory. so how static method technically call. becz obj is not in memory at the time of execution.how compiler will play with it at runtime.
will it create obj of that class or some thing other ?

how compiler will allocate space & where it will store Static Method & Variable.???


The compiler doesn't have anything to do with runtime. You use the compiler to convert your Java source code to bytecode (in a class file), which you do before runtime.

Static method and variables are at the class level, not at the object level. You don't need an object to execute a static method. The static member variables of a class are stored somewhere in memory, but exactly how depends on the implementation details of the JVM. There's no object necessary to store them.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!