• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is memory crated at the time of static call?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic