File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Naresh Joshi
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
Ishan Pandya
Ranch Hand
Posts: 225
Java
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • 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: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain it to me in detail .
And what is a class level object ?
 
Naresh Joshi
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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: 225
Java
  • 0
  • Mark post as helpful
  • send pies
  • 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: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20205
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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: 225
Java
  • 0
  • Mark post as helpful
  • send pies
  • 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: 225
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naresh Joshi wrote:
thanks buddy, it is little bit satisfying.


Your welcome.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic