Saturday, September 28, 2013

End of the First Six Weeks

In the last few weeks I have begun to come across the many differences between Java and C++.  My first taste came with learning string manipulation.  In C++, strings were always manipulated indirectly as arrays of characters.  The String class in Java hides this internal array in favor of methods such as substring().  This was quite a paradigm shift for me, because I was used to doing all of the iteration and managing indexes myself.  In exchange for somewhat less access to the string,  string operations are much simpler to use.  I hope there aren't many times I will have to memorise the methods of a class, as I find such work arduous.

Objects in C++ are very similar to objects in Java.  Both the concept and the syntax are the same.  The only difference is that Java hides its references and pointers, while C++ does not.  Not being able to pass a pointer to a method seems like it would make some operations challenging.  On the other hand, Java's garbage collection means that the programmer does not have to worry about freeing up the memory from a reference/pointer that is not in use.  Also, some pointer constructs in C++ could be very confusing, such as a variable that is a reference to a pointer to a pointer (&**var1).  When Java hides references and pointers from the programmer it is analogous to putting anti-lock brakes on a car:  it makes Java much safer, but at the cost of performance and fidelity.  This makes Java an excellent language to learn programming with without getting caught up in the nitty-gritty of memory allocation and deallocation.

No comments:

Post a Comment