Solved

Pointer Concept

Posted on 1998-01-15
2
423 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

820 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