Java has references (java.lang.ref.Reference
). Anytime you declare an object variable, you are implicitly using a reference to the memory address of that object on the heap. From section 4.3.1 in the JLS: "The reference values (often just references) are pointers to these objects...". According to wikipedia "a pointer is a programming language data type whose value refers directly to (or 'points to') another value stored elsewhere in the computer memory using its address". So Java references are pointers in the general sense, but not in the specific sense of what are called pointers in C/C++.
So now to actually answer the question, "Why are there no pointers?" Assuming you mean pointers in the C/C++ sense, this would be better phrased as "Why can't you reference/manipulate a raw memory address in Java?" And the answer is security: you don't want misbehaving programs (or hackers) being able to manipulate memory addresses directly
Java is not compiled to an platform-specific binary but to bytecode which can only be executed in a JRE (JVM). Each JVM is platform-specific and acts as the intermediary between the Java bytecode and the system, allowing Java to be platform-independent
References
http://www.linkedin.com/groupAnswers?viewQuestionAndAnswers=&discussionID=54050559&gid=70526&commentID=52874399&trk=view_disc&ut=0pse6oSsE1WAU1
No comments:
Post a Comment