Results 1 to 13 of 13
  1. #1
    gabri is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default static are instance variables

    I would like to discuss with someone this points:

    static attributes and methods of a class are converted at runtime to instance attributes and methods of that class.

    primitive types and reference types are objects.

    Excuse me if any of these was treated before.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    So what exactly do you want to discuss, as neither of those are correct.

  3. #3
    gabri is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default

    ok only for the first point, where do those static attributes and methods are stored?

    do you agree they must be part of an object?

  4. #4
    gabri is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default

    Its hard for me to explain.
    When i declare static methods and attributes, there must be an object that contains them to use them, isn't it?
    After reading a bit JLS, i found that in Class initialization, static members are "incarnated" in the Class object.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Class is also an "object", although one that you do not, normally, directly instantiate. The Class object that represents that Type is where the static methods and variables exist.

    They are associated with the Class, not with any one instantiaed instance of that Class.

  6. #6
    gabri is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default

    How's that association?
    Aren't they "injected" to the class instance??
    I said class instance, not instance of the class :)

  7. #7
    jverd is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default :headdesk:

    This was answered thoroughly in Sun's Java forums. I assume you are the same OP.

    Reposting in another forum won't change the fact that primitives are not objects, nor will it change any of the other correct and thorough explanations you were given. If there's something you didn't understand about them, post your questions clearly and concisely in your original thread and they will be addressed.

  8. #8
    jverd is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by gabri View Post
    static attributes and methods of a class are converted at runtime to instance attributes and methods of that class.
    No, they're not. I don't know where you got that idea. I can only assume you're inventing it on the fly as a way to try to force-fit Java into your perception of it.

    primitive types and reference types are objects.
    No, they're not.

  9. #9
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default Fyi

    Hi masijade, long time no see! It may interest you to know that the OP recently raised this issue on Suns own Java forums, and got rather abusive when he failed to get the response he wanted

    forums.sun.com/thread.jspa?threadID=5335355

    What's missing is the now-deleted other thread where he announced his intent to get banned, and proceeed to slander several members of the forum with an amount of profanity

  10. #10
    jverd is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by gabri View Post
    Its hard for me to explain.
    When i declare static methods and attributes, there must be an object that contains them to use them, isn't it?
    Nope. Not sure why you'd think that.

    Perhaps you think that all "data" must be stored in objects. That's not the case. An object only needs to hold object-specific data. Class variables (static member variables) are held in the Method Area of memory, as described in java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6656. This is where per-class information is stored, including the code for *all* methods--both static and non-static, and class variables. (Instance method code--non-static methods--can be stored there because executable code is read only.) The only thing that goes into objects on the heap is per-object data--instance member variables--and, depending on the implementation and what you view as composing an "object" at the level of VM memory allocation, some sort of pointer/reference/handle to the class definition for that object.
    Last edited by jverd; 09-29-2008 at 09:34 PM. Reason: Added detail.

  11. #11
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by gabri View Post
    Its hard for me to explain.
    When i declare static methods and attributes, there must be an object that contains them to use them, isn't it?
    After reading a bit JLS, i found that in Class initialization, static members are "incarnated" in the Class object.
    Correction: it was pointed out to you at great length by someone else, and you cherry-picked the bits of it you thought would support your bizarre idea that static members are instance members, somehow

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by georgemc View Post
    Hi masijade, long time no see! It may interest you to know that the OP recently raised this issue on Suns own Java forums, and got rather abusive when he failed to get the response he wanted

    forums.sun.com/thread.jspa?threadID=5335355

    What's missing is the now-deleted other thread where he announced his intent to get banned, and proceeed to slander several members of the forum with an amount of profanity
    Hey george. I didn't notice that one, but, somehow, it doesn't surprise me. The "thoughts" mentioned in the OP seemed (however far deranged) a little too contrived to be simple musing. ;-)

  13. #13
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    I'm guessing our hero here must've realised that since other people than the ego-junkie scumbags at Sun.com thought he was talking rubbish, then maybe he was.

Similar Threads

  1. accessing instance variables from static methods
    By ravian in forum New To Java
    Replies: 7
    Last Post: 03-01-2009, 10:09 PM
  2. Using Static Variables
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:08 PM
  3. Local Variables for a static method - thread safe?
    By mikeg1z in forum Advanced Java
    Replies: 1
    Last Post: 11-16-2007, 01:06 AM
  4. significance of static variables and methods
    By imran_khan in forum New To Java
    Replies: 4
    Last Post: 08-02-2007, 09:52 AM
  5. Help with static variables
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 06-28-2007, 05:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •