If you already have a String , there is no need to encode and decode it straight back, the string is already the result of someone having decoded raw bytes.
In the case of a string literal, someone is a compiler that reads your source as raw bytes and decodes it in the encoding you specify. If you physically saved the source file encoded in Windows-1252, and the compiler decodes it as Windows-1252, all is well. If not, you need to fix this by declaring the correct encoding for the compiler when compiling the source ...
Line
String utf8 = new String(accentedE.getBytes("utf-8"), Charset.forName("UTF-8"));
Absolutely nothing. (Encode as UTF-8, decode as UTF-8 == no-op)
Line
utf8 = new String(accentedE.getBytes(), Charset.forName("UTF-8"));
Encodes a string as Windows-1252, and then decodes it as UTF-8. The result should only be decoded in Windows-1252 (because it is encoded in Windows-1252, duh), otherwise you will get strange results.
Line
utf8 = new String(accentedE.getBytes("utf-8"));
Encodes a string as UTF-8, and then decodes it as Windows-1252. The same principles apply as in the previous case.
Line
utf8 = new String(accentedE.getBytes());
Absolutely nothing. (Encode as Windows-1252, decode as Windows-1252 == no-op)
An analogy with integers that might be easier to understand:
int a = 555; //The case of encoding as X and decoding right back as X a = Integer.parseInt(String.valueOf(a), 10); //a is still 555 int b = 555; //The case of encoding as X and decoding right back as Y b = Integer.parseInt(String.valueOf(b), 15); //b is now 1205 IE strange result
Both of them are useless, because we already have what we need before doing any code, the integer 555 .
There is a need to encode your string into raw bytes when it leaves your system, and there is a need to decode raw bytes into a string when they enter your system. No need to encode and decode back in the system.