Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default encoding of the JVM?

Is UTF-8 the default encoding in Java?
If not, how can I know which encoding is used by default?

like image 459
user67722 Avatar asked Jun 17 '09 10:06

user67722


People also ask

What is default encoding in Java?

The native character encoding of the Java programming language is UTF-16. A charset in the Java platform therefore defines a mapping between sequences of sixteen-bit UTF-16 code units (that is, sequences of chars) and sequences of bytes.

Does Java use UTF-8 or UTF-16?

encoding attribute, Java uses “UTF-8” character encoding by default. Character encoding basically interprets a sequence of bytes into a string of specific characters. The same combination of bytes can denote different characters in different character encoding.

What is the default encoding in Linux?

Linux represents Unicode using the 8-bit Unicode Transformation Format (UTF-8). UTF-8 is a variable length encoding of Unicode. It uses 1 byte to code 7 bits, 2 bytes for 11 bits, 3 bytes for 16 bits, 4 bytes for 21 bits, 5 bytes for 26 bits, 6 bytes for 31 bits.


Video Answer


2 Answers

The default character set of the JVM is that of the system it's running on. There's no specific value for this and you shouldn't generally depend on the default encoding being any particular value.

It can be accessed at runtime via Charset.defaultCharset(), if that's any use to you, though really you should make a point of always specifying encoding explicitly when you can do so.

like image 168
Andrzej Doyle Avatar answered Oct 13 '22 07:10

Andrzej Doyle


Note that you can change the default encoding of the JVM using the confusingly-named property file.encoding.

If your application is particularly sensitive to encodings (perhaps through usage of APIs implying default encodings), then you should explicitly set this on JVM startup to a consistent (known) value.

like image 38
Brian Agnew Avatar answered Oct 13 '22 09:10

Brian Agnew