Prev: Valuation of Stocks
Next: Database development
From: Jack on 24 Apr 2010 13:26 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
From: Arne Vajhøj on 24 Apr 2010 14:10 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
From: markspace on 24 Apr 2010 14:50 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++.
From: Lew on 24 Apr 2010 16:36 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
From: Joshua Cranmer on 24 Apr 2010 18:51
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 |