Tutor profile: Anissa A.
Subject: Java Programming
Why is there no concept of a destructor in Java?
The difference is that Java objects are heap allocated and garbage collected. Java has a built in garbage collector the cleans up unreachable objects. This helps prevents Java programs from running out of memory, by routinely clear up space in the heap. However since there is no guarantee that an object will ever become unreachable, it would not be reasonable to create a destructor. The garbage collectors automatic deletion suffices.
Subject: Computer Science (General)
What are composition and aggregation and how do they differ?
Composition and aggregation are both associations. An object that has a composition relationship to another object, if it is related to that other object, but also doesn't have meaning alone. The first object doe not make sense as a standalone item. An example would be an engine of a car. The engine is apart of the car, but has little value alone. An object has an aggregation relationship to another object, if it is related to an object, but can be used independently. An example would be an employee and a company. An employee can work for a company, but can work for several companies.
Subject: C++ Programming
Why are the lengths of single dimensional arrays often passed with the arrays? For example, sort(int arr, int length) is a user function that sorts arrays. Why is the length passed versus calling length on the array arr?
The answer relates back to the pointers and what it means to pass an array in C++. When you are passing an array in C++, you are not passing the whole block of memory. You are only passing a pointer to the first element in the array. This means that the information regarding the length of the array is no longer available via length. In order to ensure that the correct length is used for the array, it is often passed as an argument.
needs and Anissa will reply soon.