• Post Reply Bookmark Topic Watch Topic
  • New Topic

No Pointers!  RSS feed

 
harish rocky
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can anyone please tell me why there are no pointers in java?

Thank you.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This recent discussion may interest you.
 
milan chovatiya
Greenhorn
Posts: 24
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for security reasons read below
pointers basically points to some physical(real) location in your memory in your machine not logical memory(like memory on stack or array without new operator)
now if you download applet or other java program which is having pointers and execute it in your machine they can point to some of your private memory location which you never want.....firewall concern will be there
your machine can get hacked......i know you would be started thinking thank god there are no pointers.....
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a number of possible reasons.

Many people find pointers hard to understand. The designers of the Java programming language wanted to create a language that was easy to understand; many features of Java were inspired by C++, but they left a number of the more complicated features out. Pointers in C and C++ are also a frequent source of bugs, leading to the program crashing when it tries to dereference a pointer that doesn't point to a valid data structure.

Having direct pointers like in C or C++ makes it very hard to have garbage collection. For garbage collection to work, Java needs to keep track of how many references there are to an object. If you would have pointers that you could do pointer arithmetic with, it would be very hard to keep track of if there are any pointers pointing to an object. Also, the garbage collector sometimes moves objects in memory, so that the address of an object might change. Any direct pointers to the object would suddenly not be valid anymore if an object is moved.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!