Solved

Pointer Concept

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selenium docs api java index 3 97
jsp CRUD operations with and without prepared statement also hibernatge 1 50
jmeter usage 4 63
JDBC performance 8 35
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

739 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