What exactly do you want to know? eg:
If I add a single boolean variable to my class how much bigger is each instance I create?
If I write a single boolean to a file how big is the file?
If I write eight booleans to a file how big is the file?
What's the largest array of booleans I can create in a Megabyte of memory?
Java is a high level language remember. It's not C, you can't define record-like structures where you control the bit/byte placement of every item.
If you need to do some ultra-efficient boolean packing you can use shift/mask operators to pack single bits into ints that you can read/write as bytes to I/O streams
JamesCherrill, thank you for correcting my answer. I am wrong. But, in Java what is the memory size of boolean data type in bits ?
I have just checked a Text Book "Java How to Program" by Deitel and Deitel. It is said:" The representation of a boolean is specific to the Java Virtual Machine on each computer platform." Can I say:"the memory size for boolean varies on different computer platform"?
James is right, this is taken from Suns Java tutorials on Primitive Data Types:
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
Can I say:"the memory size for boolean varies on different computer platform"?
No, when someone asks you the size of a boolean, you state exactly what is stated in the JVM spec, no more, no less. This is because saying that "it varies on different platforms" would be more or less claiming that the change in platform would result in a change in the size of a boolean which isn't true.
Different VM implementations carry out optimizations which might result in a boolean occupying anywhere from 1 byte to 4 bytes (in case of a padding gone bad). I did read somewhere that some VM implementations translate a boolean to an int when writing out the class file. Not to mention that things get even more complicated when we consider 32/64 bit CPU with 32/64 bit OS combination. :-)
This is exactly the reason why people prefer using BitSet instead of an array of booleans; less overhead since each true/false bit is represented as a single bit always in BitSets.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...