aspose file tools
The moose likes Beginning Java and the fly likes is memory crated at the time of static call? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "is memory crated at the time of static call?" Watch "is memory crated at the time of static call?" New topic
Author

is memory crated at the time of static call?

nikunj jhala
Greenhorn

Joined: Nov 18, 2006
Posts: 9
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

Joined: Nov 18, 2006
Posts: 679

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
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: is memory crated at the time of static call?
 
Similar Threads
k&b master exam doubt
confusion in if condition
deserialization and casting
mock test question about passing null as method parameter
instance varibles and static methods????