Redian新闻
>
what's inside an java object?
avatar
what's inside an java object?# Java - 爪哇娇娃
f*e
1
Coming from c++ world, I am confused :->
A c++ object contains all the data members and the vtable(if exists). The
methods are just like c function sitting somewhere, with the difference of
taking an addition hidden arguement(this). There is only one copy of each
method, which is shared by all the objects of the same class.
Is a java object the same? It's not clear to me, and I couldn't google the
right answer. The few java developers I asked, they seems not care about the
mechanics(typical ja
avatar
c*t
2
You need to know more about Java first. If you are really interested,
get a java disambler (like Jasmine) and play with it a bit.

the
the
answer.
machine
This

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

avatar
g*g
3
I think data and methods are in different location.
However, it's true that the detailed implementation
is not important, which is also true for most C++ developers.

the
the
answer.
machine
This

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

avatar
r*l
4
If you want to learn Java, try to figure out what is OO first.
From the way you explained C++ object, you don't seem to know
the concept of OO at all.

the
the
answer.
machine
This

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

avatar
s*e
5

the
the
answer.
machine
This
Basically you can think that java uses the same four areas as c++ does. heap
, code, data, and stack. As I know, the method code are shared. But how to
organize the memory is kind of depending on the jvm vendor in java. Usually
this is not important if you are not writing jvm or doing some fancy thing
such as dynamic replacement of an active class.
java uses metadata object to store the refelction data of a class. The
metadata object itself is also a subclass of obj

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

avatar
L*r
6
Generally, the memory layout of Java object has the header and body.
The header has a reference to the class which defines the method.
The body is almost same as a non-vf/vb C++ object as what you already know.

the
the
answer.
machine
This

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

avatar
m*t
7

the
the
answer.
I for one don't know and don't care about the run-time memory layout of Java
objects - because I can't pretty much do anything about it even if I did.
Besides, different JVMs may choose to implement it differently.
machine
This
Remote "references" are implemented completely differently from the object
references within the same JVM.
Each JVM may choose to implement late binding differently, but I think most
of the implementations are based on virtual tables, just like in C++.

【在 f*****e 的大作中提到】
: Coming from c++ world, I am confused :->
: A c++ object contains all the data members and the vtable(if exists). The
: methods are just like c function sitting somewhere, with the difference of
: taking an addition hidden arguement(this). There is only one copy of each
: method, which is shared by all the objects of the same class.
: Is a java object the same? It's not clear to me, and I couldn't google the
: right answer. The few java developers I asked, they seems not care about the
: mechanics(typical ja

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。