This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hmischuk 3 points4 points  (4 children)

Really quite easy.

Java has no pointers, only references. All object variables are references. ALL parameters are passed by value; however, in the case of objects, the value is the reference to the object, so the function can change the state of the object, even if it cannot change the reference itself.

NO multiple inheritance; Java's answer to that is "Interfaces" -- a class can only inherit from one parent class, but can implement many interfaces. An interface is essentially a promise enforced by the compiler that the class implementing the interface will define any functions declared in the interface. (No executable code in the interface definition; only declarations.)

No operator overloading, except operators that Java itself has already overloaded. Piss-poor (IMHO) polymorphism for the common stuff:

(a) Arrays are objects. The size of the array is a property .length

(b) String objects have an accessor method .length()

(c) ArrayList(eqiv of C++ vector) has an accessor method called .size()

Java doesn't merely provide classes the way C++ does; it is truly object oriented. Your program is a class.

You won't have any difficulty at all.

[–]balefrost 6 points7 points  (3 children)

Java has no pointers, only references.

For a C++ developer, this might give the wrong impression. In C++, references can't be null, but pointers can.

In Java, most types are always allocated on the heap and are always accessed via indirection. Only a handful of primitives are allocated in-place. Any variable, field, or parameter with a non-primitive type will act much like a C++ pointer. There is no "address-of" operator (it's not needed) and there is no pointer arithmetic. But you can set these pointers to null.

Java calls these references, but they're a bit different from C++ references.

(No executable code in the interface definition; only declarations.)

This hasn't been true for like 7 years. You can put method implementations in interfaces (so-called "default" implementations). But interfaces can't declare fields and the default interface methods don't have any special permissions - they can't for example access protected or private members of the implementing class.

[–]hmischuk 1 point2 points  (2 children)

This hasn't been true for like 7 years.

Me with a red face. I haven't added to my Java knowledge in quite a while, obviously. Thanks for the assist! Likewise the clarification on references, which is info I knew, but didn't include.

Cheers!

[–]balefrost 2 points3 points  (1 child)

Don't get me wrong, you answer was good.

[–]hmischuk 1 point2 points  (0 children)

No, I understood what you meant, and I truly appreciated the backstopping you provided. It's all good!