1. How many bytes does an int occupy with Heapbytebuffer?
Accounted for 4 of them. and whether you put 1 or 1 or 0xffff.
Because the length of int is 4 Byte,heapbytebuffer storage is also a byte array.
2. Use Heapbytebuffer to put char in a few bytes?
The same 1, is two, because the length of Char in Java is 2byte.
In the same way, both the English character and the save Chinese characters occupy 2 bytes.
Sample code
Bytebuffer buff = bytebuffer.allocate (1024*1024); Buff.putchar (' C '); System.out.println (Buff.position ()); Buff.putchar (' Medium '); System.out.println (Buff.position ()); Buff.flip (); char ch1 = Buff.getchar (); char CH2 = Buff.getchar (); System.out.println ("CH1:" + ch1 + ", CH2:" + CH2);
How does the word ' medium ' in the previous example be encoded when running in the JVM?
See Java Virtual Machine specification
For more information, see
Is the "Unicode encoding used by the Java language" referring to the Jvm?.java file?
3. What is the difference between Unicode and utf-8?
See what is the difference between Unicode and UTF-8? The title question is not very strict.
4. What are the options for the integer "Wasted Space" in 1
Refer to the Org.h2.mvstore.DataUtils.writeVarInt (bytebuffer, int) method of the H2 database for on-demand use.
Basics about the length of basic types in Java