I was wondering if I put comments in my code and when someone tried to decompile it, if they could read the comments that I put?
Asked
Active
Viewed 5,008 times
4
-
3"Sometimes I believe compiler ignores all my comments." – ChssPly76 Jan 10 '12 at 02:53
-
"Sometimes I believe the compiler is reading all my comments." – Ricardo Marimon Jan 10 '12 at 02:54
-
Duplicate of http://stackoverflow.com/questions/4032147/does-java-include-comments-on-the-compiled-code – Jonathon Reinhart Jan 10 '12 at 02:55
-
Are you afraid of what people might read in there? – Etienne de Martel Jan 10 '12 at 16:18
-
I add stuff about how my code works and I was gonna obfuscate it and if someone could read the comments, it would make it easier to deobfuscate it. – Zach B. Jan 10 '12 at 22:40
4 Answers
9
No, comments are never included as part of the compilation process. They are typically removed in some sort of pre-processing, or first-pass stage.

Jonathon Reinhart
- 132,704
- 33
- 254
- 328
5
Nope, comments are discarded by the compiler.

Paul Bellora
- 54,340
- 18
- 130
- 181
-
1If your concern is to make it difficult for someone to figure out your code by decompiling it, there is also an option not to save local variable names in the compiled code. And if you really want to get tricky, there are bytecode obfuscators. – Russell Zahniser Jan 10 '12 at 02:56
2
No. And you can verify this by using DJ Java Decompiler, for example. If you also refer to the Java Class File Format, you'll see there's no construct for storing comments.

Behrang
- 46,888
- 25
- 118
- 160
1
Comments aren't included in the .class
files, so a decompiler won't be able to produce them.

Ken Wayne VanderLinde
- 18,915
- 3
- 47
- 72