Solved

Pointer Concept

Posted on 1998-01-15
2
426 Views
Last Modified: 2012-06-27
What is the alternate logic used as pointers in java...
0
Comment
Question by:uramsi01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

617 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