Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why understand at all?

merlin_barmerlin_bar Member Posts: 136
My lecturer keeps pressing the point that in java, you dont give an instance of an object a name, you are actually naming a reference to the object.
I don't see why I should care, what difference does it make? I'm guessing its something to do with the deallocation of memory.


Thanks,
merlin_bar

Comments

  • IllcoIllco Member Posts: 382
    : My lecturer keeps pressing the point that in java, you dont give an instance of an object a name, you are actually naming a reference to the object.
    : I don't see why I should care, what difference does it make? I'm guessing its something to do with the deallocation of memory.
    :
    :
    : Thanks,
    : merlin_bar
    :

    It DOES matter, because this is the major difference between Java and other languages such as C++. It provides for a secure environment for programming.

    First, you cannot instantiate objects only classes. Such an instance is called an object (this is for purists only, but since this is a purists discussion...).

    In C++ you could really have the instance or the object available in place, just like an integer. You can also have a pointer (e.g. a reference) to the object in memory. The difference is that the referenced version can be allocated and deallocated dynamically, while the local version cannot. Furthermore, using references, you can only modify the object when you have the pointer available.

    This is where Java kicks in. Since you have only the second version, you can only access objects for which you acquired a reference. This allows garbage collection, dynamic allocation, etc. It also clears things up a bit, because you always have to instantiate via a call to the new operator. And since the references are coded such that they cannot be dereference, you cannot start to poke into memory that is not yours: security is born! Finally, it allows for easy transition of objects to other computers: internet made easy!
  • merlin_barmerlin_bar Member Posts: 136
    Thanks for that Illco,
    I knew I wasn't too far off :)


    Thanks,
    merlin_bar

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _________ { http://forcoder.org } free video tutorials and ebooks about \ Scratch Visual Basic Assembly PHP Go JavaScript Objective-C Python Ruby Swift C C# PL/SQL C++ Delphi Visual Basic .NET Perl R MATLAB Java Apex LabVIEW Hack Rust Bash D Julia Erlang Fortran Awk F# Clojure Lisp COBOL Dart Prolog SAS FoxPro Alice Lua Logo Kotlin VBScript Crystal Scheme Scala Transact-SQL Ada ABAP ML \ ________

Sign In or Register to comment.