Object-Oriented Programming Languages: Java vs. C++ Programming Language Comparison

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Java vs.

C++
Programming Language Comparison
Li Lu and Sammy Chu

Adapted from
http://www.openloop.com/education/classes/sjsu/sjsu_oop/spring01/presentation/jcCompare.ppt

Object-Oriented Programming
Languages
• Java and C++ are the most popular object-oriented
programming languages
• C++ was created at AT&T Bell Labs in 1979
• Java was born in Sun Microsystems in 1990

1
Features for Comparison
• Simple • Portable
• Object-oriented • Compiled or Interpreted
• Distributed • High Performance
• Robust • Multithreaded
• Secure • Dynamic
• Architecture Neutral • Fun

Simple
JAVA C++
• No pointer • Pointer
• No multiple inheritance • Multiple inheritance
• Automatic garbage • Manual garbage
collection collection
• No operator • Operator overloading
overloading • Goto statement and
• No goto statement and structure and union
no structure and union data structure
data structure

2
Object-Oriented
JAVA C++
• Purely object-oriented • Hybrid object-oriented
• No stand-alone data • Allows the stand-alone
and functions data and functions
• Automatically supports • Needs declare virtual
polymorphism methods explicitly

Distributed
JAVA C++
• Handles TCP/IP • External library
networking easily and supports TCP/IP
nicely, can open and networking, but much
access objects across harder to do network
the Internet via URL programming
just like a local file
system

3
Interpreted or Compiled
Java source C++ source
code code

Java compiler
C++ compiler
javac
JIT gcc, g++, cl
compiler
Bytecode

JVM Binary code


Java
interpreter OS kernel
OS kernel

Both compiled and interpreted Compiled

High Performance
JAVA C++
• 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++

4
Robust
JAVA 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 • Using pointers is
automatic garbage susceptible to memory
collection avoid hard- corruption
to-debug mistakes • No array bounds
• Array bounds-checking checking

Secure
JAVA C++
• Byte-code is verified at • Memory is handled at
run-time to ensure compile-time by
security restrictions compiler
are not violated
• Memory layout is
handled at run-time by
JVM
• Uses multiple
namespaces to prevent
hostile classes from
spoofing a JAVA
program

10

5
Architecture Neutral and Portable
JAVA C++
• Same bytecode can • Platform-dependent
run on any machine binary code cannot be
supporting JVM executed on a different
• Well-defined and fixed- machine
size data types, file • Implementation-specific
formats, and GUI and varied-size data
behavior types by platforms

11

Multithreaded
JAVA C++
• Provides native • Rely on external
multithreading support libraries for
• Concurrent applications multithreading
are quite easy • Harder to do
multithreaded
programming

12

6
Dynamic
JAVA C++
• Run-time • Needs recompile if
representation for libraries are updated
classes makes it • Load libraries when
possible to dynamically compiled
link classes into a
running system
• Loads classes as
needed, even from
across networks

13

Fun
JAVA C++
• Nice features combined • The complicated or
with the Internet even some confusing
applications make Java features make C++
programming programming error
appealing and fun prone

14

7
Conclusion

• 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 multithreading have won it a place in
the business world
• Java is logically the next step in the evolution of C++

15

You might also like