Sunteți pe pagina 1din 15

JAVA v.s.

JAVA v.s. C++


C++
Programming Language
Programming Language Comparison
Comparison
Object-oriented Programming
Object-oriented Programming Language
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
Language Feature Comparison
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 declarations collection is susceptible
• No pointers and automatic to memory leakage
garbage collection avoid • Using pointers is
hard-to-debug mistakes susceptible to memory
• Array bounds-checking corruption
• 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 on • Platform-dependent
any machine supporting binary code cannot be
JVM executed on a different
machine
• Well defined and fixed-size
data types, file formats, • Implementation specific
and GUI behavior and varied-size data
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++

S-ar putea să vă placă și