Saya baru saja mempelajari dasar-dasar c + + dan tahu beberapa perbedaan dari c + + dan java. Saya ingin pos ini untuk orang lain untuk memiliki petunjuk ketika belajar bahasa baru, baik java ke c + + atau c + + ke java. saya secara pribadi belajar java pertama dan hanya tahu yang dasar-dasar jadi bebas untuk menambahkan pada artikel ini atau hal-hal yang benar.


namespace
c + + menggunakan namespace untuk grup terkait fungsi dan kelas-kelas dan untuk menghindari konflik nama variabel.

namespace name {
 //function and classes here
}

java menggunakan paket ke grup kelas terkait, karena segala sesuatu di java adalah di dalam kelas. Dalam contoh ini yang seperti di dalam namespace namespace

package string.manip.*; //namespace manip inside namespace string
class className {
}

Include

c + + menggunakan file header untuk memasukkan kode yang sudah ditulis sebelumnya dan untuk dapat menggunakan potongan ini kemudian.

#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

pointer digunakan di c + + untuk mengakses data dalam memori,di java saya pikir tidak ada hal seperti itu meskipun saya tidak yakin.:D

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 c++ foo() disebut function

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.

Semoga Bermanfaat..
Hi, I’m admin

One Comment

  1. 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:

Leave a Reply

Your email address will not be published. Required fields are marked *