0

I have some Greek comments in the code and when I enter a Greek letter it says "Save us UTF-8"

Then if I do so and re run the program the previously displayed Strings would not work properly.

For example I'm working on an encryption algorithm(Simplified Des) and this is what I get with the Cp1252 encoding in the text editor as output:

ÅO [áa[aá»j×jt
INFO BOB 57674

the first line is the encrypted version and the second is the decrypted version this is what I get when I change the encoding to UTF-8

�O [�a[a�j�jt
���NFO���BOB���7���74

I don't understand what's going on here, I've never seen anything like this before. Can someone help me? Thank you in advance

ksm001
  • 3,772
  • 10
  • 36
  • 57
  • You can try to force Eclipse to use UTF-8 for Java source files. Go to preferences, General -> Content Types, expand Text and find Java Source File. Set Default Encoding to UTF-8. – tcb Jan 05 '13 at 03:39
  • Are you reading/writing from and into files using java.io.Reader and java.io.Writer ? – Jawher Jan 05 '13 at 11:27
  • I tried changing the default to UTF-8 but it didn't matter at all. The greek comments were displayed properly however my code wasn't printing the correct results. My encryption is very low level which means that it works by manipulating bits. There are many shifts, left, right XORS, AND and OR operations done repeatedly in order to achieve the final results. I'm not sure whether the problem is in that I'm manipulating the bits and the compiler doesn't recognize some of the bit sequences and thus instead of printing the correct value it prints something else... – ksm001 Jan 05 '13 at 15:01

1 Answers1

1

There's (at least) one discussion here on SO about Should source code be saved in UTF-8 format or not.

Personally, I'd advise against it. I'd much rather use the \uXXXX notation to encode those Greek characters in the source code and keep the other settings untouched.

Community
  • 1
  • 1
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • thank you, I will probably stick to using the default settings if nothing changes and use English for my comments, however I still can't understand why anything like this would happen. – ksm001 Jan 05 '13 at 15:02
  • I'm not sure but I suppose you changed the setting but the affected files in the project weren't properly re-encoded and saved. So, Eclipse/Java _interpreted_ the files as UTF-8 when in fact the files contained characters that were still encoded as Cp1252. – Marcel Stör Jan 05 '13 at 15:16
  • Thank you again. I will choose your answer because it seems to solve the problem, however I tried asking the same question again with more details in order to figure out if there's a solution when using UTF-8. I have used UTF-8 before and never had any problems with it. I think I don't manipulate the bits correctly or I'm missing something which has to do with me not understanding how UTF-8 exactly works. http://stackoverflow.com/questions/14173393/java-eclipse-why-is-my-implementation-of-simplified-des-working-fine-under-cp – ksm001 Jan 05 '13 at 15:46