Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java multiple classes

Name: Anonymous 2012-01-25 12:13

http://www.youtube.com/watch?v=XqTg2buXS5o&feature=player_profilepage#t=179s

     tuna tunaObject = new tuna();



Someone care to explain why you need to type "tuna" at the beginning and "tuna()" at the end if you already stated that you're going to use the tuna class at the beggining?
I think I understand the "tunaObject" is(the variable to which you will assign the new class in the main class, right?), but the "new" is still kind of ... I don't understand it either...
:/

Name: Anonymous 2012-01-25 16:38

This is why Java sucks for teaching compared to Scheme.

Java brings together a bunch of conventions and workplace baggage that was introduced via C++. A maintenance of familiarity with related languages used in businesses promotes the language's adoption among current working programmers. Since the working programmers had to deal with things like IDL, COM, and other insane bullshit, Java's class whatever public static void main string brackets args system out println are very acceptable.

Scheme's philosophy of decomposition to smallest pieces and disregard for conventions means that the learner doesn't need to deal with ad hoc conventions and only focus on thinking algorithmically. More importantly, Scheme does its job as a high level language to hide complexity for what can be a very abstraction-friendly evaluation model. Bridging familiarity from common abstract thinking instead of rote traditions. Satori is achieved once one realizes the immense spectrum of mental complexity the language can accommodate spans from "evaluating" a number and adding some numbers, to non-deterministic evaluation, circular evaluators and virtual register machines.

>>1
Basically what it says is that there is a container that only stores instances that can identify itself as somehow coming from the "tuna" class. The container is named tunaObject (the "tuna" in tunaObject is unrelated to the tuna class and completely unnecessary), and you will store a new instance of the "tuna" class. If you omit "= new tuna()" you will have an empty tuna container.

The new operator is the instantiation operator. In most languages with this it is an explicit memory allocation operation. It is probably best understood that to some degree a class is a coupling of memory allocation directives with compile-time or run-time mapping of names to relative addresses, plus other language specific features.

In C++, objects can be heap or stack allocated, assignments of the form "a = tuna()" in C++ is a direct memory copy, called a copy constructor (as in, not what Java does). In C++ objects of form "= new tuna()" performs said allocation and returns a number representing a memory address through the assignment, and assigns to a pointer variable which could be "tuna * obj". new is not a C++ invention, however, as it is present in Simula-67. In C++, objects allocated with new should eventually be deleted, in Java this is not the case.

Depending on how you look at it, it can be seen as strictly convention. In Java there is no stack allocated objects at all, so the pointer type convention is dropped, turning C++ "tuna * obj" to "tuna obj". Java maintains the new operator anyway for explicit object allocation.

In some other languages, classes are actually just pure objects themselves, so the new operation would have similar semantic implications but omitting it would have a different effect altogether.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List