Solved

Pointer Concept

Posted on 1998-01-15
2
420 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 50 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
Receive file in Servlet 1 36
countAbc challenge 9 49
topping3 challenge 14 50
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now