By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Primitive Type Sizes

P: n/a
Ken
Hi. Does the Java spec mandate set sizes for primitive types (e.g.,
int, float, char, etc.)? I know the ANSI C++ standard does not do
this, which makes these sizes compiler dependent. So I guess I'm
trying to figure out if in Java these sizes are compiler or JVM
dependent.

Thanks!

Ken
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"Ken" <kk****@yahoo.com> wrote in message
news:51*************************@posting.google.co m...
Hi. Does the Java spec mandate set sizes for primitive types (e.g.,
int, float, char, etc.)? I know the ANSI C++ standard does not do
this, which makes these sizes compiler dependent. So I guess I'm
trying to figure out if in Java these sizes are compiler or JVM
dependent.

Thanks!

Ken


The size of Java a primitive is set in stone and is not dependent on the
JVM.

boolean: 1 bit
byte: 8 bit
char: 16 bit
short: 16 bit
int: 32 bit
long: 64 bit
float: 32 bit
double: 64 bit
Jul 17 '05 #2

P: n/a
"Murray" <pa***@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
news:40**********************@news.optusnet.com.au ...
"Ken" <kk****@yahoo.com> wrote in message
news:51*************************@posting.google.co m...
Hi. Does the Java spec mandate set sizes for primitive types (e.g.,
int, float, char, etc.)? I know the ANSI C++ standard does not do
this, which makes these sizes compiler dependent. So I guess I'm
trying to figure out if in Java these sizes are compiler or JVM
dependent.

Thanks!

Ken


The size of Java a primitive is set in stone and is not dependent on the
JVM.

boolean: 1 bit
byte: 8 bit
char: 16 bit
short: 16 bit
int: 32 bit
long: 64 bit
float: 32 bit
double: 64 bit

I don't think that's accurate. The *values* of primitive types are set in
stone. The range of values a byte may have is that of an 8-bit signed
two's-complement integer. That doesn't necessarily guarantee that a byte
takes exactly one byte of memory. You'd have to have a pretty good reason to
do something otherwise, but the JLS doesn't specify (I think) the space that
primitives must take up in memory. Also, I think it's more conventional that
a boolean takes one byte of memory rather than one bit.
Jul 17 '05 #3

P: n/a
Liz

"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:M6********************@texas.net...
"Murray" <pa***@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
news:40**********************@news.optusnet.com.au ...
"Ken" <kk****@yahoo.com> wrote in message
news:51*************************@posting.google.co m...
Hi. Does the Java spec mandate set sizes for primitive types (e.g.,
int, float, char, etc.)? I know the ANSI C++ standard does not do
this, which makes these sizes compiler dependent. So I guess I'm
trying to figure out if in Java these sizes are compiler or JVM
dependent.

Thanks!

Ken
The size of Java a primitive is set in stone and is not dependent on the
JVM.

boolean: 1 bit
byte: 8 bit
char: 16 bit
short: 16 bit
int: 32 bit
long: 64 bit
float: 32 bit
double: 64 bit

I don't think that's accurate. The *values* of primitive types are set in
stone. The range of values a byte may have is that of an 8-bit signed
two's-complement integer. That doesn't necessarily guarantee that a byte


So you can't run java on a cray 1 because the cray 1 is a one's complement
machine.
takes exactly one byte of memory. You'd have to have a pretty good reason to do something otherwise, but the JLS doesn't specify (I think) the space that primitives must take up in memory. Also, I think it's more conventional that a boolean takes one byte of memory rather than one bit.

Jul 17 '05 #4

P: n/a
"Liz" <Li*@nospam.com> wrote in message
news:jCPtc.5934$pt3.4744@attbi_s03...
"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:M6********************@texas.net...
I don't think that's accurate. The *values* of primitive types are set in stone. The range of values a byte may have is that of an 8-bit signed
two's-complement integer. That doesn't necessarily guarantee that a byte


So you can't run java on a cray 1 because the cray 1 is a one's complement
machine.

Can a cray 1 represent every number from -(2^7) to 2^7 - 1 (byte)?
From -(2^63) to 2^63 - 1 (long)? And so on? Of course it can. What use would
a computer be if it couldn't represent numbers. As I said, the *range* of
number is what's important. How they are represented is not dictated, and
neither is how much space is used to do so.
Jul 17 '05 #5

P: n/a
Liz

"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:zP********************@texas.net...
"Liz" <Li*@nospam.com> wrote in message
news:jCPtc.5934$pt3.4744@attbi_s03...
"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:M6********************@texas.net...
I don't think that's accurate. The *values* of primitive types are set in stone. The range of values a byte may have is that of an 8-bit signed
two's-complement integer. That doesn't necessarily guarantee that a
byte
So you can't run java on a cray 1 because the cray 1 is a one's complement machine.
Can a cray 1 represent every number from -(2^7) to 2^7 - 1 (byte)?
From -(2^63) to 2^63 - 1 (long)? And so on? Of course it can. What use

would a computer be if it couldn't represent numbers. As I said, the *range* of
number is what's important. How they are represented is not dictated, and
neither is how much space is used to do so.

I think not.
It's hard for me to remember now but I think in one's complement
that the largest negative number is one bigger than that in two's comp.
And there may be a positive and negative zero. At
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html
there is descriptive stuff about what happens when an argument is
negative zero, so I think java supports negative zero.
I do not think negative zero is possible with two's compliment integers.
Jul 17 '05 #6

P: n/a
Liz

"Liz" <Li*@nospam.com> wrote in message
news:KDcuc.12469$3x.8465@attbi_s54...

"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:zP********************@texas.net...
"Liz" <Li*@nospam.com> wrote in message
news:jCPtc.5934$pt3.4744@attbi_s03...
"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:M6********************@texas.net...
> I don't think that's accurate. The *values* of primitive types are set
in
> stone. The range of values a byte may have is that of an 8-bit
signed > two's-complement integer. That doesn't necessarily guarantee that a byte
So you can't run java on a cray 1 because the cray 1 is a one's complement machine.

Can a cray 1 represent every number from -(2^7) to 2^7 - 1 (byte)?
From -(2^63) to 2^63 - 1 (long)? And so on? Of course it can. What use

would
a computer be if it couldn't represent numbers. As I said, the *range*

of number is what's important. How they are represented is not dictated, and neither is how much space is used to do so.

I think not.
It's hard for me to remember now but I think in one's complement
that the largest negative number is one bigger than that in two's comp.
And there may be a positive and negative zero. At
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html
there is descriptive stuff about what happens when an argument is
negative zero, so I think java supports negative zero.
I do not think negative zero is possible with two's compliment integers.

Oops, I made a mistake. Seymore Cray worked at CDC prior to
forming his own company and the early CDC machines he developed were
one's compliment. By the time he designed the Cray 1, he had learned
his lesson and it was two's complement.
Jul 17 '05 #7

P: n/a
Liz wrote:


I think not.
It's hard for me to remember now but I think in one's complement
that the largest negative number is one bigger than that in two's comp.
And there may be a positive and negative zero. At
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html
there is descriptive stuff about what happens when an argument is
negative zero, so I think java supports negative zero.
I do not think negative zero is possible with two's compliment integers.


Oops, I made a mistake. Seymore Cray worked at CDC prior to
forming his own company and the early CDC machines he developed were
one's compliment. By the time he designed the Cray 1, he had learned
his lesson and it was two's complement.


It really doesn't matter if the native machine is one's complement,
two's complement or doesn't even have a notion of floating point
numbers. As long as you can write code to simulate such things on the
machine, you can write a JVM. That's the whole idea behind a virtual
machine.

Ray
Jul 17 '05 #8

P: n/a
Liz
Reminds me of the cross compiler I had to use
many years ago. It was written in FORTRAN and
the program counter was implemented as a REAL.

"Raymond DeCampo" <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:_g*******************@twister.nyroc.rr.com...
Liz wrote:

I think not.
It's hard for me to remember now but I think in one's complement
that the largest negative number is one bigger than that in two's comp.
And there may be a positive and negative zero. At
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html
there is descriptive stuff about what happens when an argument is
negative zero, so I think java supports negative zero.
I do not think negative zero is possible with two's compliment integers.


Oops, I made a mistake. Seymore Cray worked at CDC prior to
forming his own company and the early CDC machines he developed were
one's compliment. By the time he designed the Cray 1, he had learned
his lesson and it was two's complement.


It really doesn't matter if the native machine is one's complement,
two's complement or doesn't even have a notion of floating point
numbers. As long as you can write code to simulate such things on the
machine, you can write a JVM. That's the whole idea behind a virtual
machine.

Ray

Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.