Roshan Amadoru

Greenhorn
+ Follow
since Dec 18, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Roshan Amadoru

Naren,

That's not true. Because, even in 1st case, it allocate memory for the objects you create in a seperate location and get the address (reference) of the created object and then assign that reference value to the particular array element. It's just like this.


here what happen is "new Object()" creates a new object and returns the reference of the newly creted instance and assign that reference into the object reference variable o. so here, o is a reference variable and what "new object()" returns is a object reference.
[ February 13, 2006: Message edited by: Roshan Amadoru ]
I think there's something more to say and there are some corrections to made to "Bessa"'s reply.


"Please, could you allocate some more memory and put my object there ?"



Actually this is not 100% correct. When creating an array of objects, it doesnt requst to allocate some more memory and put the objects into it. What it does is, it request the JVM to allocate an array which we can hold references to the given type of objects. Array just hold the reference of the object, and the object exists in a seperate location..


int x = 9;
int[] dots = {3,6,x,8};



x is not an reference. as long as x is a primitive variable, x is copying it's value to the array and it doesnt called a reference variable.
[ February 13, 2006: Message edited by: Roshan Amadoru ]
swapnil paranjape,

Here, in line 5, we create an object of class Foo. It's created in the heap and it has the attribute i which is initialized to 3. then in the same line we ask JVM to cast that Foo object to a Object type instance. Casting doesnt mean that we loose any information in that casted object. Casting means that we just ask the JVM to treat the object as casted type. So, in line 4, because of created a Foo object, it will remain same eventhough we cast to Object type. only difference it, we cannot access variable i. In line 6, we cast it back to Foo type. then again, we ask JVM to treat the object as a Foo object. because it was initially a Foo object, it will retrieve the earlier setted atributes. that means , initialy i was 3 and when casting back, it retrieve the earlier value. Hope you got what i said.
[ January 31, 2006: Message edited by: Roshan Amadoru ]

Originally posted by amrita sankar:
A simple way to cast byte for numbers greater than 127 :

Divide 256 by that no.

ex: byte b = (byte)128;
Divide 256 by 128;
Result is -128.
For 129 result is -127.



Er... Excuse me!! did you say Divide?? or is it Substract??? Be ware of this kinda terrible Typo's. This should be Substract..

And yes, Abhinav Gogna... Hats off for you!
ven kaar, Hats off for you too!!!
[ January 29, 2006: Message edited by: Roshan Amadoru ]