C/java Basic
C/java Basic
‘Stack’ is a common name for the memory space in which automatic variables (and often function
parameters) are allocated.
‘Heap’ is a common name for the “free store”, the memory space where dynamic objects are allocated
(see “new” and “delete”).
The stack is used to allocate temporary objects while the heap is used by a programmer to reserve
allocation. Basically, an object in a heap is not scope dependent, it dies when you tell it to. Meanwhile,
an object on the stack is destroyed automatically when its scope ends.
The scope of memory allocated on the ’stack’ is the scope of the enclosing block. They get destroyed
when the enclosing block is finished. Thats why they are called ‘auto’ objects.int* pJ;
// executed
pJ = pI;
delete [] pJ; // now the memory in the free store (aka heap) gets released.
C does not have any classes or objects. It is procedure and function driven. There is no concept of access
through objects and structures are the only place where there is a access through a compacted variable.
c++ is object oriented.
C structures have a different behaviour compared to c++ structures. Structures in c do not accept
functions as their parts.
C input/output is based on library and the processes are carried out by including functions. C++ i/o is
made through console commands cin and cout.
C functions do not support overloading. Operator overloading is a process in which the same function
has two or more different behaviours based on the data input by the user.
C does not support new or delete commands. The memory operations to free or allocate memory in c
are carried out by malloc() and free().
Undeclared functions in c++ are not allowed. The function has to have a prototype defined before the
main() before use in c++ although in c the functions can be declared at the point of use.
After declaring structures and enumerators in c we cannot declare the variable for the structure right
after the end of the structure as in c++.
For an int main() in c++ we may not write a return statement but the return is mandatory in c if we are
using int main().
In C++ identifiers are not allowed to contain two or more consecutive underscores in any position. C
identifiers cannot start with two or more consecutive underscores, but may contain them in other
positions.
In c a character constant is automatically elevated to an integer whereas in c++ this is not the case.
In c declaring the global variable several times is allowed but this is not allowed in c++.
is-a vs -able or Interfaces are often used to describe An abstract class defines the core
can-do the peripheral abilities of a class, not
identity of its descendants. If you
its central identity, e.g. defined a Dogabstract class then
an Automobile class might Dalmatian descendants are Dogs,
implement they are not merely dogable.
the Recyclable interface, Implemented interfaces enumerate the
which could apply to many otherwise general things a class can do, not the
totally unrelated objects. things a class is.
In a Java context, users should
typically implement the
Runnable interface rather than
extending Thread, because they’re
not really interested in providing
some new Threadfunctionality, they
normally just want some code to have
the capability of running
independently. They want to create
Interfaces vs Abstract Classes