Hello friends,
Is pointer concept is there in java? If so how to use? if not why?
Pointer is not on java.
The language designers decided to abstract memory management to a higher level in Java than in C. The reason for this is that it is easy to make mistakes using pointers and other lower level memory management techniques. These mistakes can lead to bugs. hard to read code, memory leaks that waste system resources, and security issues.
Java actually does have pointers. When you declare an object without initializing it, eg String str;, you're actually getting a pointer. Using new returns a pointer as well to help with stack space when passing large objects to functions. The "pass by reference" method that Java uses to pass objects to functions? It's "pass by pointer" under the hood. Java hides all this pointer functionality to avoid the pitfalls of detailed memory management.
Java is full of pointers (every object is actually a pointer to an object state (value)).
Java just doesn't have pointer arithmetic but pointers are all over the place.
Java actually does have pointers. When you declare an object without initializing it, eg String str;, you're actually getting a pointer. Using new returns a pointer as well to help with stack space when passing large objects to functions. The "pass by reference" method that Java uses to pass objects to functions? It's "pass by pointer" under the hood. Java hides all this pointer functionality to avoid the pitfalls of detailed memory management.
Java does not have pointers. The word "pointer" only occurs twice in the JLS, and then only informally. To say Java has pointers would only confuse C programmers and frighten the children.
Java does not have pointers. The word "pointer" only occurs twice in the JLS, and then only informally. To say Java has pointers would only confuse C programmers and frighten the children.
Say no more about that darn NullPointerExce ption then :-)
This is one of those moments that .NET got it right when it was plagiarizing Java. They renamed it "NullReferenceE xception".
I consider that name even more obfuscating because it has nothing to do with
references as C++'s T& reference to a type T. It's my constitutional fundamental
right to consider them pointers but no 'rithmetic ;-)
Everyone who said that every object in Java is a pointer is correct. A pointer is just an address in memory at which information is stored. Unlike C and C++, pointers are abstracted. That means that it is impossible to explicitly declare a pointer. At the same time it is also easier because there is no need to worry about memory management because of the garbage collector takes care of clearing memory and memory allocation is automated as well.
Everyone who said that every object in Java is a pointer is correct. A pointer is just an address in memory at which information is stored. Unlike C and C++, pointers are abstracted. That means that it is impossible to explicitly declare a pointer. At the same time it is also easier because there is no need to worry about memory management because of the garbage collector takes care of clearing memory and memory allocation is automated as well.
since sasimca007 ask about pointers, i think he/she knows C or C++, he/she was just asking if the pointer he/she have used in C/C++ was also in java...
A pointer is just an address in memory at which information is stored. Unlike C and C++
You're correct, but no abstract pointer in java that can be used to link such addresses...
since sasimca007 ask about pointers, i think he/she knows C or C++, he/she was just asking if the pointer he/she have used in C/C++ was also in java...
You're correct, but no abstract pointer in java that can be used to link such addresses...
Correct me if im wrong,
Sukatoa
The best advice you can give a C/C++ programmer moving to Java is to forget ever thing they know about pointers; every hack and fudge and weird pointer arithmetic, and void*, and arrays via pointers and function pointers and ...
Comment