This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Instance vs Static Variables, Methods, Constructors? Basic understanding 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 "Instance vs Static Variables, Methods, Constructors? Basic understanding" Watch "Instance vs Static Variables, Methods, Constructors? Basic understanding" New topic
Author

Instance vs Static Variables, Methods, Constructors? Basic understanding

Matt Hazan
Greenhorn

Joined: Jan 27, 2011
Posts: 29
Hello everyone.

I have a test coming up very soon and I was wondering if anyone would be kind enough to explain each of the following to me in way that is easy to understand? I found some explanations online but they are a tad bit beyond my what I can comprehend as far as Java goes.

*Instance Variables (Fields)
*Instance Methods
*Static Variables (Fields)
*Static Methods
*Constructors


Thank you very much!
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That is a very big question which isn't easy to explain. Luckily the are a lot of good tutorials out there. This is a great example. I would read that and then come back if you still have questions.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

To boil it down...
  • "instance" is associated with a specific object (i.e., an "instance" of a class).
  • "static" is associated with a class, regardless of how many -- if any -- instances might be created.
  • Constructors are code that "instantiate" (create) an Object and prepare that object for use.


  • But as Wouter pointed out, the implications are far reaching. Let us know if you have specific questions.


    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
    Jesper de Jong
    Java Cowboy
    Bartender

    Joined: Aug 16, 2005
    Posts: 12929
        
        3

    From the tutorial that Wouter quoted, this part explains the difference between non-static and static members: Understanding Instance and Class Members.

    And Providing Constructors for Your Classes explains constructors.


    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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
     
    subject: Instance vs Static Variables, Methods, Constructors? Basic understanding
     
    Similar Threads
    what is a member variable
    why can't static class fields be serialized?
    By convention - are there for exemple first variables, second getters and setters and third methods?
    Program Structure
    static member variable of a class