# Other Languages > Java >  How many bytes in memory a string occupy in Java language?

## Brooklyn

How many bytes in memory a string occupy in Java language?
Suppose i write:
String name="Bill Gates";
So, how much memory it requires? Whether it can store a UNICODE character in the string. How internally it is implemented, using a 1 byte char array or 2 byte Unicode char array? I read somewhere that Java's char data type is 16 bit wide.

Thanks!!!

----------


## FunkyDexter

Thread moved.  The code bank forums are for your code submissions rather than questions.

----------


## techgnome

Indeed it is,
http://docs.oracle.com/javase/tutori...datatypes.html

char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

-tg

----------


## dilettante

Except when it is UTF-8.

Data extracted using a String.getBytes() call defaults to the platform default, which is ANSI on Windows ("Windows-1252") and UTF-8 on most *nix platforms.  Of course you can use String.getBytes("UTF-8") to be specific and work on all platforms.

But yes, String itself is always UTF-16... though it can vary between the LE and BE variations based on platform.

Not understanding these platform issues is why some plinkers get frustrated.  They ignore them and then find that their programs are not portable.  This is why pros get paid.

----------

