browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need Java help?

Get answers from our community of Java experts on BYTES! It's free.

Primitive Type Sizes

Ken
Guest
 
Posts: n/a
#1: Jul 18 '05
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



Murray
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Primitive Type Sizes



"Ken" <kk_oop@yahoo.com> wrote in message
news:510b0c84.0405280539.6ded060@posting.google.co m...[color=blue]
> 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[/color]

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


Ryan Stewart
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Primitive Type Sizes


"Murray" <parps@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
news:40b75cba$0$1585$afc38c87@news.optusnet.com.au ...[color=blue]
> "Ken" <kk_oop@yahoo.com> wrote in message
> news:510b0c84.0405280539.6ded060@posting.google.co m...[color=green]
> > 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[/color]
>
> 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
>[/color]
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.


Liz
Guest
 
Posts: n/a
#4: Jul 18 '05

re: Primitive Type Sizes



"Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
news:M6GdnVliJ8JNJird4p2dnA@texas.net...[color=blue]
> "Murray" <parps@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
> news:40b75cba$0$1585$afc38c87@news.optusnet.com.au ...[color=green]
> > "Ken" <kk_oop@yahoo.com> wrote in message
> > news:510b0c84.0405280539.6ded060@posting.google.co m...[color=darkred]
> > > 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[/color]
> >
> > 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
> >[/color]
> 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[/color]

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


Ryan Stewart
Guest
 
Posts: n/a
#5: Jul 18 '05

re: Primitive Type Sizes


"Liz" <Liz@nospam.com> wrote in message
news:jCPtc.5934$pt3.4744@attbi_s03...[color=blue]
> "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> news:M6GdnVliJ8JNJird4p2dnA@texas.net...[color=green]
> > I don't think that's accurate. The *values* of primitive types are set[/color][/color]
in[color=blue][color=green]
> > 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[/color]
>
> So you can't run java on a cray 1 because the cray 1 is a one's complement
> machine.
>[/color]
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.


Liz
Guest
 
Posts: n/a
#6: Jul 18 '05

re: Primitive Type Sizes



"Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
news:zP-dnae0YOZF5yXdRVn-ig@texas.net...[color=blue]
> "Liz" <Liz@nospam.com> wrote in message
> news:jCPtc.5934$pt3.4744@attbi_s03...[color=green]
> > "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> > news:M6GdnVliJ8JNJird4p2dnA@texas.net...[color=darkred]
> > > I don't think that's accurate. The *values* of primitive types are set[/color][/color]
> in[color=green][color=darkred]
> > > 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[/color][/color][/color]
byte[color=blue][color=green]
> >
> > So you can't run java on a cray 1 because the cray 1 is a one's[/color][/color]
complement[color=blue][color=green]
> > machine.
> >[/color]
> 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[/color]
would[color=blue]
> 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.
>
>[/color]
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.


Liz
Guest
 
Posts: n/a
#7: Jul 18 '05

re: Primitive Type Sizes



"Liz" <Liz@nospam.com> wrote in message
news:KDcuc.12469$3x.8465@attbi_s54...[color=blue]
>
> "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> news:zP-dnae0YOZF5yXdRVn-ig@texas.net...[color=green]
> > "Liz" <Liz@nospam.com> wrote in message
> > news:jCPtc.5934$pt3.4744@attbi_s03...[color=darkred]
> > > "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> > > news:M6GdnVliJ8JNJird4p2dnA@texas.net...
> > > > I don't think that's accurate. The *values* of primitive types are[/color][/color][/color]
set[color=blue][color=green]
> > in[color=darkred]
> > > > stone. The range of values a byte may have is that of an 8-bit[/color][/color][/color]
signed[color=blue][color=green][color=darkred]
> > > > two's-complement integer. That doesn't necessarily guarantee that a[/color][/color]
> byte[color=green][color=darkred]
> > >
> > > So you can't run java on a cray 1 because the cray 1 is a one's[/color][/color]
> complement[color=green][color=darkred]
> > > machine.
> > >[/color]
> > 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[/color]
> would[color=green]
> > a computer be if it couldn't represent numbers. As I said, the *range*[/color][/color]
of[color=blue][color=green]
> > number is what's important. How they are represented is not dictated,[/color][/color]
and[color=blue][color=green]
> > neither is how much space is used to do so.
> >
> >[/color]
> 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.
>[/color]
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.


Raymond DeCampo
Guest
 
Posts: n/a
#8: Jul 18 '05

re: Primitive Type Sizes


Liz wrote:[color=blue][color=green][color=darkred]
>>>
>>>[/color]
>>
>>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.
>>[/color]
>
> 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.
>
>[/color]

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
Liz
Guest
 
Posts: n/a
#9: Jul 18 '05

re: Primitive Type Sizes


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" <rdecampo@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:_gnuc.270342$M3.18285@twister.nyroc.rr.com...[color=blue]
> Liz wrote:[color=green][color=darkred]
> >>>
> >>>
> >>
> >>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.
> >>[/color]
> >
> > 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.
> >
> >[/color]
>
> 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[/color]


Closed Thread