Search This Blog

17 June, 2011

Array in java part 1

Part:- 1


The Following are examples of c++.
eg.1:-


void main()
{
int *p;
p=(int *) 6352;
*p=545;
}


The aove code gets compiled.
In the above example a memory location is being assigned to pointer p. Then through the pointer 545 is assigned to that particular location to which p points.
This is dangerous because the location might be within the scope of another application in a multi tasking environment.


Now examine the following code:-


class Bulb
{
// Some members
};
void main()
{
Bulb *p;
p=(Bulb*)6352;
*p=545;    // this line doesn't get compiled. 
}


The above code doesn't get compiled because through a class pointer a value can't be assigned to a location.


As per the above examples a pointer of simple data type can cause security problems because a value can be put up at any location through a simple data type pointer whereas this can't happen through a complex data type (class) pointer.


Because of this reason Java doesn't provide support for simple data type (long, int , short, byte, double, float, char and boolean) pointers.
Java provides support for complex data type (class) pointers.
                                                         Continue with part 2

No comments:

Post a Comment

Meetme@