Does Java include comments on the compiled code?

2020-03-14 02:25发布

问题:

Well, the title is self-explanatory. I wondered this while compiling a project which has a lot of lines commented. It's a bit silly because the jar file wouldn't increase much (some bytes) but I'm curious if this could affect a program with a lot of code and comments.

Thanks

回答1:

It would not affect the execution or performance (unless you have commented out the wrong statements :-)

But it definitely would affect readability. There is no reason to have large blocks of commented out code (in production), version control is the way to go

See this question also.Question closed.



回答2:

No, comments normally are stripped out in any language (not just in Java). They have no representative in byte code. What stays in there, is annotated stuff and such



回答3:

No, documentation isn't included in the compiled class file.

The javadocs can be generated with the javadoc program. All javadoc will be converterd to HTML.



回答4:

No, this is not added.

However, you should consider to kill dead code (i.e. commented code, but also unused code). If you think that "maybe I will need that method again", simply delete the method, and if you really need this method some day, use you SCM tool (Subversion, Git, CVS or whatever) to retrieve this old code...



回答5:

Yes JAVA includes comment in the compiled code because without including how it will come to know that whether this is a comment or not . But after including the commented line is not sent to compiler directive for compilation.