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.