Perbedaan antara C++ dan Java
namespace
c + + menggunakan namespace untuk grup terkait fungsi dan kelas-kelas dan untuk menghindari konflik nama variabel.
|
|
Include
#include "mystringmanip.h"
Walaupun paket java menggunakan namespace, ia juga bertindak seperti file header.
import java.io.*;
Arguments to main
di c + + argc adalah jumlah argumen dan argv adalah string argumen pada sebuah array
int main(int argc, char* argv[])
di java args secara otomatis objek sebagai array
public static void main(String args[])
Desctructor
in c++ ~classname()
in java void finalize()
Passing arguments to function
c + + lewat args dengan nilai tetapi masih dapat melewati referensi dengan operator &.
java secara otomatis lulus primitif (int, char, boolean) dengan nilai dan dengan referensi untuk obyek
Pointers
Delete[] / garbage collection
di c + + yang selalu pekerjaan para programmer adalah untuk membebaskan memori yang dialokasikan. di java, pengumpulan sampah dilakukan secara otomatis ketika data di memori sudah tidak ada cara untuk mengaksesnya. meskipun Anda dapat memaksa seorang pengumpulan sampah atau menetapkan nol ke suatu objek.
Terminologies
di java disebut method
dalam java lapangan adalah anggota dari sebuah kelas yang menggambarkan objek.
di c + + foo () dipanggil template di java yang disebut generics.
Yeah, in my honest opinion, they are completely different and I think it's stupid to compare. They each have their own place in the coding world. But syntactically and in style, they are rather similar. The both do perform instructions given. If that is enough to compare something, it might as well be compared. IMHO though, Java uses a virtual machine which then sends instruction to the native computer to execute. This (in my eyes) is like saying, "Hey, I see a road to the finish line!" and then someone else saying, "Who cares! Let's take the super long extra scenic route! It's pretty and has rails to protect us!". Though this analogy can be bad. C/++ can be safe if the developer we're to take the time invest in it where as Java forces it on you. C++ is also more flexible because of this but I've yet to figure out which is better in general. The reason being is that there are people (even on this forum probably) who execute functions and expect them to be perfect and DON'T EVEN CARE to take error checking into consideration. In Java this is bad but in C++, there can be serious consequences which I don't think people understand. Most libraries prevent this but for the library developers that do this and for those that play with native controls, you should think twice. Fortunately, most sane C and C++ developers do take this into consideration and anyone who doesn't is kicked off from there group or is told to f#$k off when releasing software.
Even then, there are languages that don't go the VM route and compile directly to ASM that have type and safe checking to stop the developer from making idiotic mistakes that will affect the user. I personally see no reason for Java other than platform flexibility. That's why the moment I put research into this, I stopped and learned something that might not go out of style in the near future. ASM and C/++ with a side of D for the win.:a: