Garbage collection in Java is a low priority task, so if your running application is in a situation where more memory space is required, there may be a conflict (read: 'crash') when the garbage collection cycle has not completed before your application requires additional memory. Although pointers can be dangerous in the wrong hands, if you are a disciplined programmer, you can 'free' the pointers as soon as they are no longer required, so that memory is available for your application. I program in C, C++, and Java and actually prefer working with pointers, but I learned (the hard way) to be disciplined in their use.
A longer and very interesting discussion that answers your question can be found on Stack Overflow : http://stackoverflow.com/questions/8080617/why-doesnt-java-have-pointers
Actually, Java *only* supports pointers. Any name in Java is a reference to an object allocated in garbage-collectable memory. What it doesn't provide is a direct name for a location, because it never allows you to use a specific location.
No, look at the JVM instructions. Even the primitive types are allocated dynamically and referenced. The difference is subtle, but consider something that gets autoboxed: if the only reference is from an autoboxed object, when the autoboxed object loses its reference, the GC follows to the primitive and GCs it too.
Sorry, you misunderstood me. *When* something is autoboxed, ithe compiler is creating an Object automagically around the primitive type. The point is that *every* name in Java is a reference to some allocated object, not a "name" in the sense that a name in C actually represents an address. So in C, you need a pointer type so you can distinguish between them --
int i;
int * ip = &i ;
and now ip is a reference, a name (and allocated location) for i, and contains i's address. However, if you free(ip) the world ends.
If you wanted, you could also write
int * ip = malloc(sizeof(int));
Now you have the same effect -- ip is a reference to an int's worth of memory -- but it's in the heap and can be freed.
In Java, when you write
int i = 42 ;
i is a reference to some "malloc'ed" memory even though it's a primitive, and can be GC'd later.
I think it would be good to know why you want a language to support pointers? Pointers to memory management is quite like gotos are for control structures. There are hardly any situations where you need them. So, thank God, that Java is not leaving pointers open like its predecessors of C/C++.
Garbage collection in Java is a low priority task, so if your running application is in a situation where more memory space is required, there may be a conflict (read: 'crash') when the garbage collection cycle has not completed before your application requires additional memory. Although pointers can be dangerous in the wrong hands, if you are a disciplined programmer, you can 'free' the pointers as soon as they are no longer required, so that memory is available for your application. I program in C, C++, and Java and actually prefer working with pointers, but I learned (the hard way) to be disciplined in their use.
Yeah, to some extent the lack of pointers and an explicit dtor in Java is "training wheels". In fact I just this second was having a discussion where having confidence *when* the finalize happens would be safer. (Basically, if you need to construct three things, and only get two so you want to release those.)