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 12:16

Learn inheritance and you'll understand.

And java is shit.

Name: Anonymous 2012-01-25 12:24

Mostly it's just extra typing, but occasionally it's useful if you want to create an object of a different class. The Object class can be cast to any compatible object type, somewhat like void* in C.
Object o = new Integer(10);
int i = ((Integer)o).intValue();

Name: Anonymous 2012-01-25 12:24

>>2
And what does inheritance have anything do with it?

Name: Anonymous 2012-01-25 12:35

>>4
Casting.

class Person { ... }
class Woman extends Person { ... }
class Man extends Person { ... }

Person bob = new Man();
Person alice = new Woman();

Name: Anonymous 2012-01-25 12:39

>>5

class Person { /* ... */ }

class Woman extends Person { /* ... */ }
class Man extends Person { /* ... */ }

Person bob = new Man();
Person alice = new Woman();


Assuming this is Java or the like, one can also have implemented interfaces:

interface SoundMaker {
    public void makeSound();
}

class Beeper implements SoundMaker {
    public void makeSound() {
        /* beep */
    }
}

class Booper implements SoundMaker {
    public void makeSound() {
        /* boop */
    }
}

SoundMaker soundMakerInstance = new Beeper(); // or Booper

Name: Anonymous 2012-01-25 12:42

>>5
Then why did he write

tuna tunaObject = new tuna()

instead of

apples tunaObject = new tuna()

?

Name: Anonymous 2012-01-25 12:44

>>7
Person you = new MentalMidget()

Name: Anonymous 2012-01-25 13:04

Someone here is a mental midget.

Name: Anonymous 2012-01-25 13:13

OP truly is a toilet scrubber.

Name: Anonymous 2012-01-25 13:34

OP is not a satori of dubs

Name: Anonymous 2012-01-25 14:05

new is a holdover from C++

It's even stupider that it's in JS and Dart.

Name: Anonymous 2012-01-25 14:22

>Java

Why are you using a language intended to teach CHILDREN how to program?

C/C++ master race reporting in.

Name: Anonymous 2012-01-25 14:30

>>13
C++

Fuck off and go back to /g/ you mental midget.

Name: Anonymous 2012-01-25 15:16

>2012
>static typing

JEWS

Name: Anonymous 2012-01-25 15:20

>>1

In Java and C++ you have to repeat the type name umpteen times to get anything done, because this is 1960's technology.

The compiler is like a retarded child that needs constant guidance through verbal repetition and reminding.

This garbage is behind the state of the art in static type systems by 40 years.

Name: Anonymous 2012-01-25 15:56

>>16
``If Java had true garbage collection, most programs would delete themselves upon execution.''

Name: Anonymous 2012-01-25 16:07

Tuna tuna = new Tuna();
Is more correct, class names usually begin with a uppercase letter.

Tuna is the "type" of the variable tuna in this case.

You could have:
Object tuna = new Tuna();

Since the Tuna class is also an Object. All classes implicitly extends Object.

You could have a superclass Fish for example,
and declare Tuna as:

public class Tuna extends Fish {
..
}

then you could treat all Tunas as Fishes.

Fish fish = new Tuna(); etc..

but then only the fish methods of tuna would be visible through that variable.

TLDR:
I suck at explaining things.

Name: Anonymous 2012-01-25 16:15

``If you are not scared of subtyping, you do not understand it.''

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.

Name: Anonymous 2012-01-25 16:46

>>18
I was just going to write that I didn't understand what you were saying until I saw your tl;dr.

I just wish someone could answer my question in >>7 instead of giving replies that you're accustomed to give on /b/.

At least answer me this and tell me which of the next statements that I'm thinking are wrong:

In tuna tunaObject = new tuna()
"tuna" stands for the class I'm calling
"tunaObject" defines what type of .... thing... tuna is(like classifying "23" as a string/int/double)
"new" IDK what this is, I suppose it just is to let python know that it's a new function or something.
"tuna()" I'm assuming that it's just there in case I want to have that class examine a variable or an input and I can do that by putting whatever I want examined between the parentheses.

Name: Anonymous 2012-01-25 16:57

>>20
Oh, I missed your post because apparently you posted it after I refreshed the page and started to write >>21
I think I now understand a little bit better.
So basically if the class I want to call is called "tuna" then "tuna" and "tuna()" in tuna tunaObject = new tuna() must be called explicitly "tuna" but tunaObject can ba called whatever I want?

Name: Anonymous 2012-01-25 17:06

>>21
I think the best language for teaching "101" is python. Enforcing the indentation to beginners is good, as most of the beginners are too stupid to understand why indentation is necessary. Also it carries most of the benefits you counted.

If you say we should ignore the ones who cannot even comprehend the necessity of indentation and focus on the ones who can appreciate the beauty of lisp; yes, I agree with you.

Name: Anonymous 2012-01-25 17:13

>>23
I was learning python, until I found out that coding in python for android is far more complex than learning java and coding using that since I would have to learn how to use android SDK and NDK. SO I decided to put python on hold till I can code on java.

But as you said, I found python to be a very enjoyable experience, especially since I don't have to waste time declaring variables as single/double/int/string/etc.

Name: Anonymous 2012-01-25 17:14

>>18
More to the point, it's a "reference type".

Name: Anonymous 2012-01-25 17:36

>>20
You've never actually written any kind of Java software for a living have ya?

Name: >>20 2012-01-25 18:06

>>26
Used to, actually. (is this a meme?)

Name: Anonymous 2012-01-25 18:42

>>27
Just kodak-kun and kodak-wannabes (read: spammers).

Name: Anonymous 2012-01-25 19:08

>>27
No, I read the following...

>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.

And my first reaction was "Oh geeze, this person is pulling that one out of their ass".

Name: Anonymous 2012-01-25 19:34

Let's take this apart:

tuna tunaObject // we are making a variable called tunaObject that is of type tuna
= new tuna(); // And assigning it to an object made by the tuna constructor function, which must be named tuna.

Why does this not make sense to you?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-25 19:46

>>30
tuna tunaObject // we are making a variable called tunaObject that is of type tuna

That's a reference variable you mental midget.


= new tuna(); // And assigning it to an object made by the tuna constructor function, which must be named tuna.

That's not a 'constructor function' you idiot. A function in Java, even one that is void, will always return something. In contrast a construct returns nothing. Not even void!

Why does this not make sense to you?

Far clearer, concise, and more correct explanations have already been given. Why you felt the need to give your own moronic and incorrect response goes beyond me.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-25 19:47

>>31
*a constructor returns nothing.*

Name: Anonymous 2012-01-25 21:17

check muh mental midget dubdubs

Name: Anonymous 2012-01-25 21:26

it is useful for "polymorphism"

Name: Anonymous 2012-01-25 21:37

>>30
So when you make a class it becomes a new data type itself which you use to declare new variables?
Does that mean there are classes for String, double, int, etc?

That's what doesn't make sense to me.

Name: Anonymous 2012-01-25 21:47

>>35
In before the minimum wage toilet scrubbers....

>So when you make a class it becomes a new data type itself which you use to declare new variables?

No. When you have something like...

Tuna tunaObject = new Tuna();

new Tuna() creates an Object. tunaObject is a 'reference variable' that refers to this new object.

Does that mean there are classes for String, double, int, etc?
There are classes for String, Double, and Integer.

Name: Anonymous 2012-01-25 21:49

>>35
Of course this would all be easier if you would have read the great titty book known as SICP. This is because all of this bullshit is more or less message passing. Ie, you create an object and then you use methods to get and send data to this object.

Name: Anonymous 2012-01-25 21:56

>>36
Then what's the purpose of the first instance of "tuna" in that line?!

Name: Anonymous 2012-01-25 22:08

>>38
Something like..

Tuna tunaObject = new Tuna();

Can be broken down like the following...

new Tuna() creates a new Tuna Object. Tuna tunaObject creates a 'reference variable' called tunaObject of type Tuna.

Name: Anonymous 2012-01-25 22:09

It's very useful
especially when making [b]VIDEO GAMES[/b]

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