On programming

<< < (7/11) > >>

benguela (June 01, 2011, 20:35:00 PM):
Hmm, the only way I can think of to create a linked list using Java is if each node is itself an instance of the same object class that references the node after it (and the node before if it’s doubly-linked).

See, not that difficult. But wow do they struggle with this.

BoogieMonster (June 01, 2011, 23:51:44 PM):

Being strictly OO, Java doesn’t recognise pointers, which is how I’d do this normally. Then again, everything in Java except operators...

Forgive my rude assumption about your knowledge here but actually Java has non-object types, there's both a primitive int type, and an Integer class. A lot of the primitives you'd find in C/C++ are available as types in Java too: short, long, char, etc...

Also, (memory don't fail me now...) unless specifically coded otherwise, object variables are just references, so you can get your "pointer like" linked list by accident... A fact many Java novices don't grok at first sight, until it's "pointed" out.
Mefiante (June 02, 2011, 11:38:10 AM):
Are you saying that Java actually supports pointer types, even if only inadvertently? Surely you wouldn’t be able to dereference such a pointer explicitly in Java! And wouldn’t all of that fly directly in the face of the abstractions that OOP is all about!?

I’m hardly a Java boffin, not having used the language much at all. I could be wrong here, but it is my impression that in Java even “primitive” data types like int come bundled with some methods, e.g., “toString()”. If so, they’re hardly primitives in the sense of C, Pascal, BASIC, etc. Or is that the “Integer” class I’m thinking of?

As for object variables being references, that is true for all OO languages I’m aware of. It’s just that the languages’ syntax rules hide the pointer nature of object variables from the programmer. A disassembly of Delphi or C++ code (or Java to byte code or C# to MSIL) makes it quite plain that objects are always passed by reference in the compiled code. If the programmer actually intends passing an object by value to a function, the function transparently creates a local copy (not on the stack, though!) of the object from the original which it then operates on and later destroys, but the original is still passed by reference, i.e. as the object’s base pointer. What I was driving at is that Java, like C#, adheres very strictly to OO standards, whereas other OO languages not so much. Although not good practice, one can mix OOP with straight procedural code in C/C++ and Delphi. As far as I know, in Java or C# you cannot do this, or other wild things such as for example directly accessing an object’s VMT, but you can in Delphi or C++ if you know how to use pointers and how the objects are represented in memory. (You might actually want to do the latter for detailed on-the-fly debugging purposes in certain circumstances.)

'Luthon64
BoogieMonster (June 02, 2011, 14:55:29 PM):
I’m hardly a Java boffin, not having used the language much at all. I could be wrong here, but it is my impression that in Java even “primitive” data types like int come bundled with some methods

Nope.

Quote
Or is that the “Integer” class I’m thinking of?

Yup.

Quote
It’s just that the languages’ syntax rules hide the pointer nature of object variables from the programmer.

That's my point, to make a new object you need to invoke "new" explicitly (iirc). My comment was about novices who fail to realise that "MyObject b = a;" is not a value copy, but results in two references to one object (if it wasn't a primitive).
Deezil (June 02, 2011, 15:38:34 PM):
omg ... reading this thread just made me realise again how glad I am I got out of programming a looong time ago.

Thanx guys!

P.S Used to program in Cobol in the late 90's and doddled a bit with java and c# while studying in the mid 00's (nothing hectic though ... reading the two posts above was like (wtf!!))

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Skeptic Forum Board Index

Non-mobile version of page