• 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

how does jvm behaves with static variables, methods and inner classes?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have listen this "Java is not pure object oriented because of primitive types",
but what about the static fields ?
Does jvm provides an object for them or not ?
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A class level Object is assigned to static fields.
you must have heard a class level lock in threading for static fields.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch If you search this forum for “pure object oriented”, you find many people have asked the same question before.
You would have to read the JVM specification to find whether the location of static members is specified. I think static fields live in the Class object, as do all methods. I presume static nested classes have Class objects of their own, referenced from the surrounding class’ Class object, bit I am not certain.
 
Naresh Joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain it to me in detail .
And what is a class level object ?
 
Naresh Joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch If you search this forum for “pure object oriented”, you find many people have asked the same question before.
You would have to read the JVM specification to find whether the location of static members is specified. I think static fields live in the Class object, as do all methods. I presume static nested classes have Class objects of their own, referenced from the surrounding class’ Class object, bit I am not certain.



My question does not concern with why java is pure oop language or not,
In all the discussion everybody is telling java is not pure oop because of primitive types(because they are not objects).
What i am asking is static fields and methods are also not related to objects so why we do not give this reason ?
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These static fields belong to an OBJECT. this object is a Class Level object.
Each class has it own "Class" object which can be obtained by ClassName.class
The static members belong to this object.
This is my understanding. Not pretty sure about it but still.

do have a look at this Java.lang .Class

thanks
 
Naresh Joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ishan Pandya wrote:These static fields belong to an OBJECT. this object is a Class Level object.
Each class has it own "Class" object which can be obtained by ClassName.class
The static members belong to this object.
This is my understanding. Not pretty sure about it but still.

do have a look at this Java.lang .Class

thanks


thanks buddy, it is little bit satisfying.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ishan Pandya wrote:These static fields belong to an OBJECT. this object is a Class Level object.
Each class has it own "Class" object which can be obtained by ClassName.class
The static members belong to this object.
This is my understanding. Not pretty sure about it but still.

do have a look at this Java.lang .Class

thanks

Why are you quoting Java 1.4? that has been superseded over 8 years ago.
The static fields do not really belong to the Class object. They belong to the class which corresponds to the Class object.
Yes, you can get the Class object by ClassName.class.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Naresh Joshi wrote:In all the discussion everybody is telling java is not pure oop because of primitive types(because they are not objects).
What i am asking is static fields and methods are also not related to objects so why we do not give this reason ?



You could do that, if you liked. But the debate about whether Java is "pure" OOP or if not, why not, is in my opinion not very useful. It inevitably gets bogged down in a mess of competing definitions. However if this helps you to understand static members a little bit better, then it isn't a complete waste.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why are you quoting Java 1.4? that has been superseded over 8 years ago.


Ohh..Really sorry about that.. I just searched it directly from google and pasted the link.

The static fields do not really belong to the Class object. They belong to the class which corresponds to the Class object.


I got it.

 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Naresh Joshi wrote:
thanks buddy, it is little bit satisfying.



Your welcome.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Naresh Joshi wrote: . . . thanks buddy, it is little bit satisfying.

But, as I said last night, little bit inaccurate too.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic