Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do your javadocs get compiled into your class files?

When you compile your java files, does it also embed your javadocs and comments into the class file?

For example, if you have large javadocs, does it effect the overall size of your class file? Or does the compiler ignore everything beginning with // and /* ?

like image 451
Jimmy Avatar asked Nov 09 '10 14:11

Jimmy


People also ask

How to create a Javadoc?

To create a JavaDoc you do not need to compile the java file. To create the Java documentation API, you need to write Javadoc followed by file name. After successful execution of the above command, a number of HTML files will be created, open the file named index to see all the information about classes.

How to compile a class file in Java?

You can not compile a *.class file, Its already compiled code (bytecode) for its *.java source. I think you need to copy the code from JD Decompiler's editor to a java source file. i.e. copy the source code from JD's editor for Hello.class into a file named Hello.java .

What are the parts of a Javadoc?

It has two parts: – a description which is followed by block tags. To create a JavaDoc you do not need to compile the java file. To create the Java documentation API, you need to write Javadoc followed by file name.

Can a java file have more than one class?

As we know that a single Java programming language source file ( or we can say .java file) may contain one class or more than one class. So if a .java file has more than one class then each class will compile into a separate class files. For Example: Save this below code as Test.java on your system.


2 Answers

No. There are several debug options that affect the size of a class file but the comments are never part of the resulting .class file.

Some estimate:

  • -g:line just adds line number information (a few bytes)
  • -g:vars includes the full names of all variables. This is usually the most expensive option.
  • -g:source just adds the name of the source file (without path).

Note: -parameters makes names of method parameter accessible via reflection. This is independent of -g:vars.

Comments (and therefore JavaDoc) are never added to the bytecode.

To see what ends up in the .class file, use javap -v plus the path of the file.

like image 157
Aaron Digulla Avatar answered Oct 05 '22 10:10

Aaron Digulla


No, the class file is just binary data.

Annotations may be retained (depending on the annotation).

Comments won't affect the size of the class file.

like image 41
Jon Skeet Avatar answered Oct 05 '22 08:10

Jon Skeet