Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

While completing your research on multiparadigm languages in Module 2, you selec

ID: 3721253 • Letter: W

Question

While completing your research on multiparadigm languages in Module 2, you selected three languages (C++, Java, Python ) used in industry that interested you (C++, Java, Python ).

For this project, you will write code.

If you choose to code, you will write small code that displays the major difference between two languages in two different paradigms.

When comparing languages, for either option, you need to compare at least three concepts.

Examples include: garbage collection method, implementation models used, types used, and parameter passing methods.

Make sure you do not compare syntax differences.

Explanation / Answer

1) Compilation of programme in JAVa and C++

At compilation time java code converts into byte code. Interpreter execute the byte code and give output.

C++ compiler directly converts bytecode to machine code. so it is faster than java. This is the reason C++ is platform depedant and java is platform independent

2)Garbage Collection in C++

In C++ delete and free command are used for deallocation memory or for garbage collection

psuedo code :

int x;

int *ptr1 = &x;

int *ptr2 = (int *)malloc(sizeof(int));

int *ptr4 = NULL;

delete ptr1;

delete ptr4;

getchar();

return 0;

}

Garbage collection in JAVA

Java doesn't have destructor

Garbage collection is done automatially by JAVA.

If you want to force fully run you can use below command

1) Using gc()

2) Using finalize()

3) Passing parameter

C++ is both pass by value and pass by reference

Pass by reference c++

#include <iostream>

using namespace std;

void swap(int& x, int& y)

{

int z = x;

x = y;

y = z;

}

// function definition to swap the values using pass by value

void swapbyValue(int x, int y) {

int temp;

temp = x;

x = y;   

y = temp;

  

return;

}

int main()

{

int a = 15, b = 25;

cout << "Before Swap value ";

cout << "a = " << a << " b = " << b << " ";

//swap(a, b);

swapbyValue(a,b);

cout << "After Swap with pass by reference Example values are ";

cout << "a = " << a << " b = " << b << " ";

  

}

#include <iostream>

using namespace std;

void swap(int& x, int& y)

{

int z = x;

x = y;

y = z;

}

void swapbyValue(int x, int y) {

int temp;

temp = x; /* save the value of x */

x = y; /* put y into x */

y = temp; /* put x into y */

  

}

int main()

{

int a = 15, b = 25;

cout << "a = " << a << " b = " << b << " ";

swap(a, b);

swapbyValue(a,b);

cout << "a = " << a << " b = " << b << " ";

}

Java is pass by value