top of page

C++ VS JAVA

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


Java compiler usage



C++ vs. Java: differences



C++ vs. Java: differences …



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?

7 views0 comments

Recent Posts

See All
Post: Blog2_Post

learning with arya

Subscribe Form

Thanks for submitting!

©2023 by [Business Name]. Proudly created with Wix.com

bottom of page