Compare Java and C++
Anonymous
Java Methods versus C++/C Functions -------------------------------------------------------- In Java every method must be an instance of a class or a static method. C++ can do that too, but you can also declare functions as global functions. In Java, method arguments are ALWAYS passed by value. In C++, you can pass both by value or by reference. Passing by reference meaning, the function can modify the original. Java Objects versus C++ Objects -------------------------------------------------- In C++, object variables hold values not references. Furthermore, new operator is not used to create a new instance of a class. Rather you simply provide the class name and the constructor with optional parameters. The syntax is also different when defining a class. Most notably is the fact you have scope areas in C++ and in Java you have to specific about each member variable or method's scope (i.e. private int data; ) Java versus C++ data types and variables ------------------------------------------------------- C++ has data types that get more granular, like short or long and unsigned. C++ has string data types and Java has a String data types. In C++, you can directly modify strings. Java you CANNOT. Lastly, the C++ compiler doesn't care if you didn't initialize a local variable - the prog should still compile. C++ Pointers versus Java pointers ------------------------------------------------ No pointer arithmetic allowed in Java. The creators of Java at Sun decided that there were too many problems with the people trying to use this feature in C++, so they said "NO!" C++ pointers behave similar to Java objects in that they are both references. Also you don't have to worry about cleaning up after allocated memory in your heap, because the Java garbage collector is basically like my mom, it will clean up after you whether you asked her to or not. =) Just remember, the garbage collector will only deal with objects that no longer have a reference to it (i.e. it is pointing to NULL or the same). You have to take care of this yourself in C++ using the delete function. Similarly, you can access an illegal index in C++, since C++ doesn't do run-time checks for bad index values. Basically - if you are a irresponsible programmer - stick to Java!!!
Check out your Company Bowl for anonymous work chats.