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.

Friday, September 13, 2013

The First Three Weeks

The first three weeks of AP Computer Science have mostly been review from my knowledge of C++.   Java borrows most of its syntax from C++, so it has been very easy learning about the basics of programming in Java such as variables, operators, and methods.  What has been challenging is learning all of the idiosyncrasies of how Java methods handle various types.  The worksheets have been very useful in this regard, but I still sometimes have trouble with specific cases.  One such case is when a character is added to an integer and the result is printed, for example: System.out.println('A' + 5).  The result is an integer, not a character.  This is very different from System.out.println("A" + 5), where the output is the string "A5".  I am not sure how many of these idiosyncrasies will be on the AP test, but I think I should try to learn as many as possible just in case.

I have also been able to set up the various editors I will use to do labs this year.  I had already had some experience with Eclipse, so I decided to use that as my primary editor.  The complication with using Eclipse, however, is that each compile unit has to be in its own project.  I did not want to create projects for each lab, so I created a generic project called lab where I would do each of my labs one at a time.  When I finished with a lab, I saved it into a new .java file following Mr. Steven's naming conventions.  I think this will work well for the first labs which are short, but I am not sure that this scheme will work for larger projects.  In that case, I will have to create separate projects.

Weston