Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pointer Concept

Posted on 1998-01-15
2
Medium Priority
?
431 Views
Last Modified: 2012-06-27
What is the alternate logic used as pointers in java...
0
Comment
Question by:uramsi01
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 150 total points
ID: 1232211
I'm assuming you're asking about how pointers work in Java, and how they are different from pointers in C.
Firstly there is a common misconception that there are no pointers in Java, which is what makes the language "safer" to use. However, this is not the case. "Safety" has been promoted by making pointers implicit, rather than explicit, and, I think just as importantly, by automatic garbage collection.
All object references in Java are, in fact, pointers. When you write:

String mystring=new String();

mystring is a pointer to an object of type string. When a method is called with a String argument, what is passed is the "pointer" mystring. So firstly Objects (and arrays) are not plopped on the stack wholesale, a reference or pointer is passed instead.
Secondly the "pointerness" of something like mystring is evidenced in comparisons. If you write:

String s1="ABC";
String s2="ABC";
if(s1==s2)System.out.println("Equal");

Equal will not print, since s1 and s2 reference different objects. Their contents can be compared with the equals method. So Object names are references. The big differrence with C is that all referencing and dereferencing (i.e. the * and & operators) is done implicitly.

0
 
LVL 1

Author Comment

by:uramsi01
ID: 1232212
Thanks imladris, for your clear description of pointer concept
in Java.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question