• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pointers

 
deepthi k
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do we have any concept of pointers in java?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define "pointer".

I've searched the JLS and the most specific use of the word "pointer" occurs in 4.3.1 (Objects):



An object is a class instance or an array.

The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object.



Note this doesn't imply that you can do C-style pointer arithmetic in Java:

Hey, remember that old t-shirt of yours with that code emblazoned across the chest?
[ December 20, 2005: Message edited by: Jeff Albrechtsen ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java language does not have pointers in the same way as you have them in C or C++ - i.e., pointers that can point to any location in memory and that you can do pointer arithmetic with.

However, Java does have references, which are essentially the same as pointers , but with a few restrictions meant to make programming and debugging safer and easier. For example, a reference must always point to a valid object or null - it can't point to any arbitrary location in memory, and you can't do tricky arithmetic with it.

Note that Java has the NullPointerException - it should have been called NullReferenceException, but now it's far too late to change the name...
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deepthi,
welcome to JavaRanch! We're a friendly bunch here, but we do have one rule that we take seriously -- the JavaRanch Naming Policy

Basically we require display names to be two words: your first name, a space, then your last name. While we prefer you use your real name, we of corse cannot enforce it. However, obviously fictitious names are not allowed.

Please edit your profile and correct your display name.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic