Java String
objects are always encoded as UTF-16. (*) This is the "native character encoding".
When converting text to a byte stream then some specific encoding must be chosen and different operating systems and their configurations have different preferences on how that is done.
Java introduces the concept of "default character encoding" which tries to represent "the character encoding that the underlying operating system considers the default".
On Android that "default character encoding" is UTF-8 (luckily this is an increasingly common default).
Java APIs (and thus Android APIs which are built on top of or using Java APIs) often use the default character encoding whenever a String
needs to be converted to a byte stream (such as when writing to a file or a network connection) and no explicit character encoding is provided.
(*) Well, there's caveats and exceptions, but those are not usually user-visible. For example JDK9 supports compact strings where String
objects that contain only ISO-8859-1 encodeable characters actually store only 8bit per character instead of 16. However this optimization (as well as a similar one implemented in newer Android versions) don't change any return values of String
, so they are transparent to the developers.