SlideShare a Scribd company logo
1 of 15
C++ vs. Java:
Similiarities & Differences
Dr. Jeyakesavan Veerasamy
Director of CS UTDesign program &
CS Teaching Faculty
jeyv@utdallas.edu
University of Texas at Dallas, USA
History
• C (1969)  C++ (1979)  Java (1995)
• Both support OOP. Most OOP library contents
are similar, however Java continues to grow.
• Syntax is very close – Java has strong influence
of C/C++. Easy to learn the other language
when you know one of these.
C++ compiler & Linker usage
file1.cpp file2.cpp filen.cpp
….
file1.o file2.o filen.o
….
Linker
application
(executable)
Compiler Compiler Compiler
C++ compiler does
not care about
filenames.
This appliction
runs directly on
top of OS.
Java compiler usage
file1.java file2.java filen.java
….
file1.class file2.class filen.class
….
Compiler Compiler Compiler
Operating System
Java Runtime Environment (JRE)
C++ vs. Java: differences
C++ Java
Write once, compile
everywhere  unique
executable for each target
Write once, run anywhere 
same class files will run above
all target-specific JREs.
No strict relationship
between class names and
filenames. Typically, a
header file and
implementation file are
used for each class.
Strict relationship is enforced,
e.g. source code for class
PayRoll has to be in
PayRoll.java
C++ vs. Java: differences …
C++ Java
I/O statements use cin
and cout, e.g.
cin >> x;
cout << y;
I/O input mechanism is bit
more complex, since default
mechanism reads one byte at
a time (System.in). Output is
easy, e.g.
System.out.println(x);
Pointers, References, and
pass by value are
supported. No array
bound checking.
Primitive data types always
passed by value. Objects are
passed by reference. Array
bounds are always checked.
C++ vs. Java: differences …
C++ Java
Explicit memory
management. Supports
destructors.
Automatic Garbage
Collection.
Supports operator
overloading.
Specifically operator
overloading was thrown out.
Types of memory used by
executable task
Code
Stack
data
(static)
heap (dynamic)
Objects
• Objects can be created as local variables just like
any basic data types in C++.
C++:
ComplexType num1;
Java: Nothing equivalent – Objects cannot be in
stack.
Objects in Heap
C++:
ComplexType *num1 = new ComplexType(…);
Java:
ComplexType num1 = new ComplexType(…);
Arrays
• Basic data types and classes are treated the
same way in C++, unlike Java.
C++: ComplexNumber numbers[5];
Java: nothing equivalent.
C++ array version #2
ComplexNumber *numbers;
numbers = new ComplexNumber[5];
Java: nothing equivalent for classes,
but possible for basic data types:
int numbers[];
numbers = new int[5];
C++ array version #3
ComplexNumber **numbers;
numbers = new ComplexNumber*[5];
for( index i = 0 ; i < 5 ; i++)
numbers[i] = new ComplexNumber(…);
Java:
ComplexNumber numbers[];
numbers = new ComplexNumber [5];
for( index i = 0 ; i < 5 ; i++)
numbers[i] = new ComplexNumber(…);
C++ vs. Java: Analogy
• Working with C++ is like flying a airpline, while
working with Java is like driving a car.
• What does it mean?
• Too many controls/options in C++: think before
use each one.
• Careful use can result in efficiency, poor use can
result in serious inefficiency
• Issues like memory leak can crash the application,
out-of-bounds array access can cause memory
corruption – but it may not show up for long time
– causing lot of headache!
• Java : slow and steady wins the race?
References
• C++ tutorials:
http://www.cplusplus.com/files/tutorial.pdf,
http://www.learncpp.com/
• C++ reference: http://en.cppreference.com/w/
• Java tutorial:
http://docs.oracle.com/javase/tutorial/
• Java API documentation:
http://docs.oracle.com/javase/6/docs/api/

More Related Content

What's hot

Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and JavaAjmal Ak
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
 
Evolution of programming language
Evolution of programming languageEvolution of programming language
Evolution of programming languageSameer Saini
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects yndaravind
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Mahmoud Alfarra
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
The Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring CloudThe Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring CloudVMware Tanzu
 
Advanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID PrinciplesAdvanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID PrinciplesJon Kruger
 

What's hot (20)

Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and Java
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Evolution of programming language
Evolution of programming languageEvolution of programming language
Evolution of programming language
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Core java
Core javaCore java
Core java
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1
 
Core java
Core javaCore java
Core java
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
The Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring CloudThe Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring Cloud
 
Java codes
Java codesJava codes
Java codes
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Oop java
Oop javaOop java
Oop java
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Advanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID PrinciplesAdvanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID Principles
 

Similar to C++vs java (20)

C++vsJava.pptx
C++vsJava.pptxC++vsJava.pptx
C++vsJava.pptx
 
C++ l 1
C++ l 1C++ l 1
C++ l 1
 
Intro to .NET and Core C#
Intro to .NET and Core C#Intro to .NET and Core C#
Intro to .NET and Core C#
 
Presentation on C++ programming
Presentation on C++ programming Presentation on C++ programming
Presentation on C++ programming
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
UsingCPP_for_Artist.ppt
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
Unit 1
Unit 1Unit 1
Unit 1
 
C# for beginners
C# for beginnersC# for beginners
C# for beginners
 
java slides
java slidesjava slides
java slides
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
C vs c++
C vs c++C vs c++
C vs c++
 
Csharp
CsharpCsharp
Csharp
 

Recently uploaded

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Recently uploaded (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

C++vs java

  • 1. C++ vs. Java: Similiarities & Differences Dr. Jeyakesavan Veerasamy Director of CS UTDesign program & CS Teaching Faculty jeyv@utdallas.edu University of Texas at Dallas, USA
  • 2. History • C (1969)  C++ (1979)  Java (1995) • Both support OOP. Most OOP library contents are similar, however Java continues to grow. • Syntax is very close – Java has strong influence of C/C++. Easy to learn the other language when you know one of these.
  • 3. C++ compiler & Linker usage file1.cpp file2.cpp filen.cpp …. file1.o file2.o filen.o …. Linker application (executable) Compiler Compiler Compiler C++ compiler does not care about filenames. This appliction runs directly on top of OS.
  • 4. Java compiler usage file1.java file2.java filen.java …. file1.class file2.class filen.class …. Compiler Compiler Compiler Operating System Java Runtime Environment (JRE)
  • 5. C++ vs. Java: differences C++ Java Write once, compile everywhere  unique executable for each target Write once, run anywhere  same class files will run above all target-specific JREs. No strict relationship between class names and filenames. Typically, a header file and implementation file are used for each class. Strict relationship is enforced, e.g. source code for class PayRoll has to be in PayRoll.java
  • 6. C++ vs. Java: differences … C++ Java I/O statements use cin and cout, e.g. cin >> x; cout << y; I/O input mechanism is bit more complex, since default mechanism reads one byte at a time (System.in). Output is easy, e.g. System.out.println(x); Pointers, References, and pass by value are supported. No array bound checking. Primitive data types always passed by value. Objects are passed by reference. Array bounds are always checked.
  • 7. C++ vs. Java: differences … C++ Java Explicit memory management. Supports destructors. Automatic Garbage Collection. Supports operator overloading. Specifically operator overloading was thrown out.
  • 8. Types of memory used by executable task Code Stack data (static) heap (dynamic)
  • 9. Objects • Objects can be created as local variables just like any basic data types in C++. C++: ComplexType num1; Java: Nothing equivalent – Objects cannot be in stack.
  • 10. Objects in Heap C++: ComplexType *num1 = new ComplexType(…); Java: ComplexType num1 = new ComplexType(…);
  • 11. Arrays • Basic data types and classes are treated the same way in C++, unlike Java. C++: ComplexNumber numbers[5]; Java: nothing equivalent.
  • 12. C++ array version #2 ComplexNumber *numbers; numbers = new ComplexNumber[5]; Java: nothing equivalent for classes, but possible for basic data types: int numbers[]; numbers = new int[5];
  • 13. C++ array version #3 ComplexNumber **numbers; numbers = new ComplexNumber*[5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…); Java: ComplexNumber numbers[]; numbers = new ComplexNumber [5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…);
  • 14. C++ vs. Java: Analogy • Working with C++ is like flying a airpline, while working with Java is like driving a car. • What does it mean? • Too many controls/options in C++: think before use each one. • Careful use can result in efficiency, poor use can result in serious inefficiency • Issues like memory leak can crash the application, out-of-bounds array access can cause memory corruption – but it may not show up for long time – causing lot of headache! • Java : slow and steady wins the race?
  • 15. References • C++ tutorials: http://www.cplusplus.com/files/tutorial.pdf, http://www.learncpp.com/ • C++ reference: http://en.cppreference.com/w/ • Java tutorial: http://docs.oracle.com/javase/tutorial/ • Java API documentation: http://docs.oracle.com/javase/6/docs/api/