Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ความแตกต่างระหว่าง C++ และ Java

Java C++
Java ถูกพัฒนาโดย James Gosling ที่ Sun Microsystems C++ ถูกพัฒนาโดย Bjarne Stroustrup ที่ Bell Labs เป็นส่วนขยายของภาษา C
ได้รับอิทธิพลจาก Ada 83, Pascal, C++, C# ได้รับอิทธิพลจาก Ada, ALGOL 68, C, ML, Simula, Smalltalk
Java bytecode ทำงานบนระบบปฏิบัติการใดๆ ไม่ทำงานบนทุกระบบปฏิบัติการ เนื่องจากไลบรารีต่างกันในแต่ละระบบ
รันบน OS ใดๆ ได้ คอมไพล์ต่างกันในแพลตฟอร์มต่างกัน ไม่สามารถรันบน OS ใดๆ ได้
เป็นภาษาที่พกพาได้ (portable) ไม่พกพาได้
เป็นภาษา interpreted เป็นภาษา compiled
จัดการหน่วยความจำโดยอัตโนมัติ จัดการหน่วยความจำด้วยตนเอง
ไม่มีคีย์เวิร์ด 'virtual' มีคีย์เวิร์ด 'virtual'
รองรับ single inheritance เท่านั้น Multiple inheritance สามารถทำได้ผ่าน interfaces (บางส่วน) รองรับ single และ multiple Inheritance
ไม่รองรับ operator overloading รองรับ operator overloading
รองรับ pointer อย่างจำกัด รองรับ pointer operations
มีฟังก์ชันระดับสูง (high level functionalities) มีฟังก์ชันระดับต่ำ (low level functionalities)
ไม่รองรับการเรียก native library โดยตรง รองรับการเรียก system library โดยตรง
รองรับ documentation comment (/**.. */) สำหรับ source code ไม่รองรับ documentation comment สำหรับ source code
รองรับ thread operations ไม่รองรับ threads โดยออกแบบ สามารถทำได้โดยใช้ third party threading libraries
ใช้คลาส 'System' เช่น System.in สำหรับ input ใช้ 'cin' สำหรับ input operation
ใช้ System.out สำหรับ output ใช้ 'cout' สำหรับ output operation
ใช้ System.out สำหรับ output (ซ้ำ) ใช้ 'cout' สำหรับ output operation (ซ้ำ)
ไม่รองรับ global scope รองรับ global scope และ namespace scope
ไม่รองรับ structures และ unions รองรับ structures และ unions
ไม่มีคีย์เวิร์ด 'goto' รองรับคีย์เวิร์ด 'goto'
รองรับ Pass by Value เท่านั้น รองรับ Pass by Value และ pass by reference
จัดการอ็อบเจกต์โดยอัตโนมัติด้วย garbage collector จัดการอ็อบเจกต์ด้วยตนเองด้วย 'new' และ 'delete'