views:

274

answers:

3

I'm after a list of issues in Java that cannot be properly understood without first understanding the difference.

For example:

  • Passing parameters to methods
  • Precisely what limitations are imposed by using "final" on a variable declaration.
  • What == means

Any more?

EDIT: this question doesn't seem to make sense to people. The motivation behind it is that my experience as a beginner learning Java was that the difference between, for example:

int i = 1;

and

Set<Thing> set = new Set<Thing>();

was not obvious. Now I know once you picked Java up you take it for granted and don't think about it but I maintain that it's something that beginners struggle with, especially if they don't come from a programming background. I think it's something that will often need to be addressed when teaching Java.

EDIT: still no good. Feel free to close.

+2  A: 

I think the most important point is to understand that references in Java do not contain the objects themselves but only an address (or pointer or whatever you want to call it) to the actual objet itself. Thus it is crucial to understand that you always have two things:

  1. The reference (which is stored in a variable)
  2. The object (which cannot be stored in a variable - only referenced by a reference)

If you understand this key concept, things like the == are quite easy to understand because now you know you're just comparing the references and not the objects.

In summary: Before teaching how to use objects explain what the difference is between an object and its reference.

Benedikt Eger
A: 

I think your question is - If you were to explain a Java feature to someone then for better explaination you would need to compare it with other feature.

For example,

== Vs .equals()

That way I think -

  • static Vs non-static
  • interface Vs class
  • synchronized Vs non-synchronized

Is this what you looking for?

Bhushan
A: 

I agree with Benedikt Eger that the relationship between references and objects is the most important concept to understand.

For your list of issues: the "=" operator can sometimes cause confusion in people, since to beginners it can appear to "copy" primitives but "share" objects. This is much less of a problem in Java than it is in C++, since "=" will never copy an object (Java does not put objects on the stack). However, I have seen "=" trip up beginners, especially when they think "=" will create a duplicate copy of an array.

Eric L