Top.Mail.Ru
June 11th, 2007 - Java developers — LiveJournal
? ?

Java developers

June 11th, 2007

07:03 pm - oracular_rufio - "References" vesus pointers

Hi, folks, I just joined this community, and I have a question:

I've done a lot of extracurricular C++ programming, but I just started in on my university's CS department, and they use Java. Talking about the differences between the two languages, my professor threw out that Java does not have pointers, but something called "references" which are "effectively the same" according to him.

So I want to know: what IS the difference (in terms of both writing the code and its interpretation by the computer)? Can I declare variables in Java that are references to objects? Can I pass arguments to functions by reference rather than by value? Can I use references like C pointers to do sneaky things like this:

int main ()
{
int *x; // pointer

if (someFunction (x)) // pass pointer to function, where value is reassigned
// code block using new value of x
}

bool someFunction (int *x)
{
// function returns false here if it was unable to proceed for some reason; otherwise:
...
...
result = *x;
return true;
// thus, the function can return the value of x and also a bool indicating that it was successful
}


(Sorry for the C++, but I think the syntax is similar enough.)
Powered by LiveJournal.com