Null pointer issues

Discussion in 'Java' started by Jack, Apr 24, 2010.

  1. Jack

    Jack Guest

    Java avoids the memory access violation suffered by C/C++. But it
    still has the null pointer issue. Certainly, this makes Java code
    safer than C/C++ code. But you can control memory directly with C/C++.
    Is there any other advantages of Java on this perspective?

    Thanks.

    Jack
    Jack, Apr 24, 2010
    #1
    1. Advertising

  2. Jack

    Arne Vajhøj Guest

    On 24-04-2010 13:26, Jack wrote:
    > Java avoids the memory access violation suffered by C/C++. But it
    > still has the null pointer issue. Certainly, this makes Java code
    > safer than C/C++ code. But you can control memory directly with C/C++.
    > Is there any other advantages of Java on this perspective?


    Garbage collection !

    Arne
    Arne Vajhøj, Apr 24, 2010
    #2
    1. Advertising

  3. Jack

    markspace Guest

    Jack wrote:

    > Java avoids the memory access violation suffered by C/C++. But it
    > still has the null pointer issue. Certainly, this makes Java code
    > safer than C/C++ code. But you can control memory directly with C/C++.
    > Is there any other advantages of Java on this perspective?



    Also, the lack of direct memory control in Java means it's really hard
    to mess up memory allocation.

    I haven't played with C++ in a while, but there's certainly some darn
    weird things you can do with memory allocation in that language. The
    guys who program in C++ all the time seem to love it, but to me it just
    looks like a opportunity to make some really serious errors and write a
    bunch of byte where they shouldn't go.

    In Java, your options are much more limited, but also much safer. You
    can allocate memory with new (which cannot be overloaded like C++):

    Object object = new SomeObject();

    or you can allocate contiguous buffers with arrays:

    byte[] buffer = new byte[256];

    And fundamentally that's all I can think of. Both these objects are
    subject to garbage collection, so there's no destructors to worry about,
    all Java methods are virtual by default, and all objects are referred to
    by reference, so copy constructors are not needed (or available, really).

    All this makes it much easier to do "real" object oriented programming
    in Java, imo, rather than have to worry about a lot of little low level
    methods or deal with memory de-allocation on a class-by-class basis,
    something I always found tedious and error-prone in C++.
    markspace, Apr 24, 2010
    #3
  4. Jack

    Lew Guest

    Jack wrote:
    > Java avoids the memory access violation suffered by C/C++. But it
    > still has the null pointer issue. Certainly, this makes Java code
    > safer than C/C++ code. But you can control memory directly with C/C++.
    > Is there any other advantages of Java on this perspective?


    You don't have to control memory directly as you do in C/C++.

    --
    Lew
    Lew, Apr 24, 2010
    #4
  5. On 04/24/2010 01:26 PM, Jack wrote:
    > Java avoids the memory access violation suffered by C/C++. But it
    > still has the null pointer issue. Certainly, this makes Java code
    > safer than C/C++ code. But you can control memory directly with C/C++.
    > Is there any other advantages of Java on this perspective?


    Direct access to memory is a mixed blessing. You can do... "crazy" stuff
    with it, but for most programs, it's not exactly something that one
    needs to be able to do. The cost of this is that you have to manage
    memory yourself--for large, complex problems, manual memory management
    results in high costs, and you may end up implementing what the JVM has
    already implemented for you.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Apr 24, 2010
    #5
  6. Jack

    Roedy Green Guest

    On Sat, 24 Apr 2010 10:26:56 -0700 (PDT), Jack <>
    wrote, quoted or indirectly quoted someone who said :

    >Java avoids the memory access violation suffered by C/C++. But it
    >still has the null pointer issue. Certainly, this makes Java code
    >safer than C/C++ code. But you can control memory directly with C/C++.
    >Is there any other advantages of Java on this perspective?


    It is impossible to write code that runs differently every time
    because you forgot to initialise something. Java either initialises
    for you or insists you do it.

    In Java it is impossible to free an object yet retain pointers to it.

    In Java it is impossible to leap into the middle of random code/data
    and start executing doing all manner of weird things.

    In Java it is impossible to have a pointer point to something other
    than what it purports to.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    It’s amazing how much structure natural languages have when you consider who speaks them and how they evolved.
    Roedy Green, Apr 25, 2010
    #6
  7. Jack

    Lew Guest

    OT: structure of natural language (Was: Null pointer issues)

    Roedy Green wrote in his sig:
    > It’s amazing how much structure natural languages have
    > when you consider who speaks them and how they evolved.


    Nonsense. When you see how much structure natural nature has overall
    (remember physics, anyone? biology?) it makes sense that any given natural
    process has structure.

    Of course, I do agree that it is amazing that nature has such structure, and
    even more amazing that we have some capability to apprehend it. But there's
    no reason to suspect or expect natural language to be any less structured than
    anything else in nature.

    --
    Lew
    Lew, Apr 25, 2010
    #7
  8. Jack

    Roedy Green Guest

    Re: OT: structure of natural language (Was: Null pointer issues)

    On Sun, 25 Apr 2010 13:42:45 -0400, Lew <> wrote,
    quoted or indirectly quoted someone who said :

    >> It’s amazing how much structure natural languages have
    >> when you consider who speaks them and how they evolved.

    >
    >Nonsense. When you see how much structure natural nature has overall
    >(remember physics, anyone? biology?) it makes sense that any given natural
    >process has structure.


    The thing I find odd is that people can speak sentences, who could not
    for the life of them parse a sentence into nouns, verbs etc. I would
    have expected human language to have evolved much simpler grammars.
    Even the stupidest people can master a very complex grammar to speak
    it. Why did so many languages for example assign arbitrary genders to
    nouns -- a pointless complication?

    This illustrates Stephen Pinker's contention that our language ability
    is hard wired.

    You can tell that people are using rules, not just memorising phrases,
    by listening to small children who regularise the grammars, e.g. I
    gived.

    Notice the difference between computer languages and natural
    languages.

    Computer languages are essentially list of commands, and information
    needed to execute the commands. Natural language is essentially a
    description of external reality, particularly the actions of humans.

    Computer languages are not big on pronouns.

    Natural languages have a canonical pronunciation.

    Computer languages are big on bracketting with () [] { }. Natural
    languages don't do nesting well.

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    It’s amazing how much structure natural languages have when you consider who speaks them and how they evolved.
    Roedy Green, Apr 27, 2010
    #8
  9. Jack

    Lew Guest

    Re: OT: structure of natural language (Was: Null pointer issues)

    Roedy Green wrote:
    > The thing I find odd is that people can speak sentences, who could not
    > for the life of them parse a sentence into nouns, verbs etc. I would


    That is no more odd nor less wondrous than that a butterfly can
    migrate to the same location thousands of miles away every year but
    for the life of it cannot point out to you which way "north" is.

    > have expected human language to have evolved much simpler grammars.
    > Even the stupidest people can master a very complex grammar to speak


    Even the smartest butterfly is stupider than that person.

    > it. Why did so many languages for example assign arbitrary genders to
    > nouns -- a pointless complication?
    >


    But ships really are female!

    Certainly the universe is.

    > This illustrates Stephen Pinker's contention that our language ability
    > is hard wired.  
    >


    Just like the butterfly's navigation ability.

    > You can tell that people are using rules, not just memorising phrases,
    > by listening to small children who regularise the grammars, e.g. I
    > gived.
    >


    --
    Lew
    Lew, Apr 27, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,599
    Mike Schilling
    Mar 29, 2006
  2. Ken
    Replies:
    69
    Views:
    12,511
    Michael D. Borghardt
    Jul 31, 2004
  3. Ken
    Replies:
    5
    Views:
    2,525
    Victor Bazarov
    Jul 24, 2004
  4. aneuryzma
    Replies:
    3
    Views:
    704
    Jim Langston
    Jun 16, 2008
  5. Christopher
    Replies:
    4
    Views:
    440
    Ruben Safir
    Jul 9, 2011
Loading...

Share This Page