JAVA V.S. C++: Programming Language Comparison

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15

JAVA v.s.

C++
Programming Language Comparison

By
LI LU
SAMMY CHU
Object-oriented Programming Language

• Both Java and C++ are most popular


object-oriented programming languages

• C++ was created at AT&T Bell Labs in


1979

• Java was born in Sun Microsystems in


1990
Language Feature Comparison

• Simple • Portable
• Object-oriented • Compiled or Interpreted
• Distributed • High Performance
• Robust • Multithreaded
• Secure • Dynamic
• Architecture Neutral • Fun
• No pointer • Pointer
• No multiple inheritance • Multiple inheritance
• Automatic garbage • Manual garbage
collection collection
• No operator overloading • Operator overloading
• No goto statement and • Goto statement and
no structure and union structure and union
data structure data structure
• No stand-alone data • Allows the stand-alone
and functions data and functions

• Automatically supports • Needs declare virtual


polymorphism methods explicitly
Handles TCP/IP networking easily and
nicely, can open and access objects across
the Internet via URL just like a local file
system

External library supports TCP/IP


networking, but much harder to do
network programming
JAVA C++
source code source code
Java compiler C++ compiler
javac JIT gcc, g++, cl
Bytecode compiler
Java JVM Binary code
interpreter OS kernel OS kernel

Both compiled and interpreted Compiled


• Much slower than C++, • About 10~20 times
but good enough to run faster than equivalent
interactively for most JAVA code
applications
• Most operating
• JIT compiler available systems are written
using C/C++
• Originally designed for • Allows implicit type and
writing highly reliable or function declarations
robust software • No automatic garbage
• Explicit method collection is susceptible
declarations to memory leakage
• No pointers and automatic • Using pointers is
garbage collection avoid susceptible to memory
hard-to-debug mistakes corruption
• Array bounds-checking • No array bounds-
checking
• Byte-code is verified at run-time to
ensure security restrictions are not
violated
• Memory layout is handled at run-time
by JVM
• Uses multiple namespaces to prevent
hostile classes from spoofing a JAVA
program

• Memory is handled at compile-time by


compiler
• Same Bytecode can run • Platform-dependent
on any machine binary code cannot be
supporting JVM executed on a different
machine
• Well defined and fixed-
size data types, file • Implementation specific
formats, and GUI and varied-size data
behavior types by platforms
• Provides native • Rely on external
multithreading support libraries for
multithreading
• Concurrent applications
are quite easy • Harder to do
multithreaded
programming
• Run-time representation
for classes makes it • Needs recompile if
possible to dynamically libraries are updated
link classes into a running
system
• Load libraries when
• Loads classes as needed, compiled
even from across networks
Nice features combined with the Internet
applications make JAVA programming
appealing and fun

The complicated or even some confusing


features make C++ programming
error prone
• C++ is a high performance and powerful
language. Most of the industry software is
written in C/C++
• JAVA’s cross-platform compatibility and
convenient APIs for networking and multi-
threading have won it a place in the business
world. Java is the logically next step in the
evolution of C++

You might also like