Null pointer issues

J

Jack

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
 
A

Arne Vajhøj

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
 
M

markspace

Jack 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?


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++.
 
L

Lew

Jack 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?

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

Joshua Cranmer

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.
 
R

Roedy Green

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.
 
L

Lew

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.
 
R

Roedy Green

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.
 
L

Lew

Roedy said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top