1

Does java support pointers? I already read some threads on this topic but those are not fully understood.

If not then why there is Null Pointer Exception?

user221234
  • 27
  • 1
  • 6
  • Java uses Call-by-value in function calls. As objects are stored on the Heap and not on the Stack, non-primitive values are always stored as pointers to the object on the heap. if there is none, it's a null pointer. – Johannes H. Jul 23 '14 at 19:43
  • Thanks @Tichodroma. Edited. I was actually referring to Java, I just answered to many JS questions in the last minutes – Johannes H. Jul 23 '14 at 19:45
  • The answer to the second half of your question is simply that the Java team got it wrong, and chose an inappropriate name for that class. It's possible that at some point, they had intended to include pointers in the language; but I guess we'll never know. – Dawood ibn Kareem Jul 23 '14 at 19:46
  • @Tichodrama, `"JavaScript" =~ /Java/` – Mike Samuel Jul 23 '14 at 19:53
  • While Java doesn't support pointers, you can access memory by address. using Unsafe on some JVM, though it is discouraged, or not allowed by the SecurityManager. – Peter Lawrey Jul 23 '14 at 20:01

2 Answers2

7

No, only references. It's not like c/c++ where we have to manage the memory management by destructors. In java automatic GC works for memory management (separate thread with main). There are some contradictions are like if java doesn't support pointers then why it's throwing Null "Pointer" Exception?

Because this thing is in JVM level. From the developer perspective java is managed by references not pointers but internally(JVM) there are pointers everywhere.

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
Deepu--Java
  • 3,742
  • 3
  • 19
  • 30
0

Firstly, ANSWER is BIG NO for Pointers.

Answering to your second question:

Java is Object Oriented Language. Where Object can be null.

Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76