Javatpoint Logo

pointer in java

By: susant*** On: Fri Jul 08 10:55:52 IST 2016     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
If java doesn't support pointer,then why in maximum case it shows "NullPointerException". If it support pointer then how ?Up0Down

 
Java does not support pointers. NullPointerException is a RuntimeException .Its a special null value can be assigned to an object reference in java.
NullPointerException is thrown when an application attempts to use an object reference that has the null value.
But, what Java does have is references, which are different from pointers.
References store an address. That address is the address in memory of the object. So, when a class is declared like so:

"StudentClass s = new StudentClass();", the "s" variable actually stores an address in memory. If you were to look at that
address in memory you would see the details of the StudentClass object. Pointers in C++, however, point directly to the object.
You can not perform arithmetic operations on references. So, adding 1 to a pointer is not possible, but is possible in C++.
Image Created0Down

By: [email protected] On: Fri Jul 08 15:00:50 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Java does not support pointers. NullPointerException is a RuntimeException .Its a special null value can be assigned to an object reference in java.
NullPointerException is thrown when an application attempts to use an object reference that has the null value.
But, what Java does have is references, which are different from pointers.
References store an address. That address is the address in memory of the object. So, when a class is declared like so:

"StudentClass s = new StudentClass();", the "s" variable actually stores an address in memory. If you were to look at that
address in memory you would see the details of the StudentClass object. Pointers in C++, however, point directly to the object.
You can not perform arithmetic operations on references. So, adding 1 to a pointer is not possible, but is possible in C++.
Image Created0Down

By: [email protected] On: Fri Jul 08 15:04:01 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No