We are about to switch to a new forum software. Until then we have removed the registration on this forum.
If a primitive type has its own class within processing itself (or java) is it not an object or float of type object and if so what differentiates it from being used like other objects? ie being able to hold multiple streams of data ect would its behaviour be controlled by the variables contained in the constructor of class float and could i initialize a primitive in the same way i would any other object eg:
float wolf ;
void setup(){
wolf = new float(2);
}
and would this be the same as saying: float wolf = 2;
Answers
Which in turn is a dynamically allocated contiguous block of memory.
Main difference between those 2 values above is on how they are represented in memory.
The
10.5
value is stored as a 4-byte memory sequence.The
-30.8
is inside a Float object placed in some contiguous memory block in the heap region.What's actually stored in variable referenceFloat is the memory address of that Float object!
Hope that's enough! O:-)
wow that's great would the array function "float[] name= new float[number]" be a reference or a primitive then? i guess the invoking the new operator is confusing me as i assume this is used to initialize only "objects" the type float is primitive and so i could see this being stored as a list of 4 byte sequences ?
Will not work because
float
is a primitive andnew
is used to create objects from classes. But this will work.Note that the wrapper classes Float, Integer, Double etc are immutable so in the following
will create two Float objects one at line 3 and a second at line 4
Arrays are objects too, although they have special treatment in Java b/c they are instantiated & accessed thru' curly braces [].
Therefore, what's stored in variable name is the memory address of that dynamically allocated memory block thru'
new
.So, where are the
float
primitive elements? Inside that array object's memory block! 8-Xthanks that clears things up alot of "new" things were brought up ;) but that definitely sorted out my query
Cheers