Friday, July 3, 2015

Why there are no pointers in Java?

Pointer is used to hold the address of a variable or object.


                              

                                                              Fig: Pointer

Pointer is very important concept of C which helps us to directly access memory location and provide a way of passing values by reference and making permanent changes in variable values which is a concept of "Pass by Reference"

Pointers can directly access the memory locations so sometimes it can be dangerous to use them,any attacker may write program ruin all your computer memory data which can create big problem for users.So, In java concept of pointers is removed. However, the same functionality can be achieved by creating object reference. 


Java has references, but not pointers

There are wrapper classes in java which  are used to convert primitive data types into objects. These objects can act as an reference.

Below is the syntax of creating object reference and object.


For eg. if the class name is Student then we will do Object Instantiation using
Student s = new Student(); Object Instantiation: Class_name obj = new Class_name
Object Reference: Class_name obj;

For more information please refer: 




No comments:

Post a Comment