Page 3 of 3 FirstFirst 123
Results 41 to 51 of 51
  1. #41
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

  2. #42
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Nice try. That's an anonymous instance of a locally declared class that implements ActionListener.

  3. #43
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Just thought of something... could an object be thought of as like a prototype. (blueprints?) Thinking from that perspective, a class is like an object that can be instantiated, it in itself is an instance of the Class object, and Class is... what is Class anyway?
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  4. #44
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default object vs instance

    I always thought that pretty much everything was an object (variables, methods, classes, instances, etc). So getting back to the OPs original question "instance vs object", wouldn't it be something like an "instance object" or an "object of instance type" ? (I'll probably get flammed for the reference to "type" as that describes int, String, etc). Just using layman terms here :)

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #45
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Here's my final post, I swear!

    "object" can mean a lot of things, depending on whether we are talking strict Java tech or in a more general sense. I almost always use "instance", just because it is specific to something that gets "instantiated".

    I think there are some *wrong* ways to use object, but I won't mention any of them because I don't want to pick at anyone (I was getting that at work until a third developer got mad two days ago and lit the dude up!) I guess that what word we use really doesn't matter, as long as everyone agrees about what it means. Getting everyone to agree is the hard part.

    I learned a lot from the discussion and from googling around on some of the issues. Bottom line, what Java does behind the scenes is very complicated, but the language does a good job of hiding it.

  6. #46
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    @Steve: I swore a long time ago not to post on this thread again... and here I am
    "object" can mean a lot of things, depending on whether we are talking strict Java tech or in a more general sense. I almost always use "instance", just because it is specific to something that gets "instantiated".
    Indeed. They are not exactly the same, but they are close enough that it does not matter too much.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  7. #47
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    OK, time for an OO programmer's dictionary:

    object - A concept broadly defined as something that has state and possible actions. In Java, an object is exactly an instance of a class. In memory, a Java object consists of just the object's fields; the code is not duplicated for every object, but stored as part of the class definition.

    class - The description of a "class" of objects. The "blueprints" of an object if you will. In Java, contains the definitions of all methods and fields, the code for all non-abstract methods, and static fields.

    instance - What you get when you instantiate a class. Synonymous with object.

    instantiate - To create an instance of something described by a class.

    type - A concept describing what kind of thing is stored in a variable. Used to prevent various evil runtime errors (what's 2+cheese?). In Java, a type can be a primitive type or a class.

    prototype - In some languages (not Java), classes are represented by a prototype object. In order to instantiate this "class" you clone the prototype and then change it's variables (rather than creating a new object that follows the class's definition).

    java.lang.Class - A particular class that Java uses to represent the concept of a class. Within the JVM, every loaded class also has a corresponding instance of type Class, though which reflection APIs can be accessed. Whether this Class object is the same as the actual class is implementation specific.

    java.lang.Object - A particular class that Java uses as the base class for all other classes (including arrays). Therefore every object is of type Object and every class extends Object.

    heap - Where objects are stored.

    static - Static things are associated (and usually stored as part of) a class rather than an object.

    reference - What Java doesn't let you see. Also called a pointer. Treated like other variables of primitive types and points to an object on the heap.

    primitive - Something represented directly, in-place, in compiled code. In essence only a number, but conceptually can be treated as characters, booleans and references. Basically, anything that isn't an object.

    literal - Something you can type into your source code directly, instead of explicitly instantiating it. All primitive types (as you can't instantiate them) as well as Strings and arrays can be used literally.

    field - A variable that's associated with a class or object, rather than on the local stack.

    interface - A class that only contains method declarations and no implementations. Cannot be instantiated. Java allows multiple inheritance only of interfaces.
    Last edited by OrangeDog; 05-29-2009 at 04:58 AM.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #48
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by OrangeDog View Post
    instantiate - To create an instance of something described by a class.

    type - A concept describing what kind of thing is stored in a variable. Used to prevent various evil runtime errors (what's 2+cheese?). In Java, a type can be a primitive type or a class.
    It might be better to say that a variable can be of two types: primitive or reference. The latter can be elaborated as class types, interface types and array types - and they can be further parameterised with type arguments. (See JLS 4.1 and 4.3).

    In a similar vein - that there is more to non primitive types than classes - instantiating can involve creating an instance (of some anonymous class) that is described by an interface rather than a class. Or, indeed, the description can occur in the optional class body block ending the class instance creation expression. Such is the case with code like

    Java Code:
    MouseListener foo = new MouseListener() { // an interface
        public void mouseClicked(MouseEvent e) {
           // etc
        }
        // etc
    };
    Last edited by pbrockway2; 05-29-2009 at 09:57 AM.

  9. #49
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Reference would be more accurate, despite what it may seem, I was trying to avoid too much discussion of internals.

    You're still instantiating a class, it just doesn't have a name. You can never instantiate an interface.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  10. #50
    bhaskar.s is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Re: difference between instance and object

    object means which has state and behaviour.
    instance created means memory allocated.

  11. #51
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: difference between instance and object

    If you haven`t come from C it`s weird but actually it`s that simple - where Class a = new Class(); "a" is simply a reference and it depends how long the object will live. Well kind of remote control to the object. Set it to null and watch garbage collectors shows it`s ugly head. Effective Java by Bloch offers interesting ways to avoid that "new" creator and it`s pretty effective.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2009, 06:14 PM
  2. [SOLVED] printing address of current instance of object?
    By emceenugget in forum New To Java
    Replies: 1
    Last Post: 02-09-2009, 09:36 PM
  3. [SOLVED] Non-synchronized instance method of an Object
    By piyu.sha in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-06-2008, 06:35 AM
  4. New Instance for SWT
    By srinivasa_v in forum SWT / JFace
    Replies: 1
    Last Post: 08-08-2007, 01:02 AM

Posting Permissions

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