The naming rules for the class file generated after Java compilation

Source: Internet
Author: User
Tags classe naming convention

Today, a classmate asked about the Java compiler generated after the. class file name problem, although the use of Java has been developed, but before the compilation of the. class file name specification also basically did not know, also really is repentance unworthy ah! I'll summarize it today anyway. Here's the experiment I did today.

1. Create class ClassA and observe the resulting. class file. The goal is to test for a. class file that does not have any inheritance, implementation classes, and internal classes.and naming rulesExperimental results: As you can see, only one. class file is generated and the file name isclass name.2, create the class CLASSB,observe the resulting. class file. The purpose is to test the. class file that is generated by implementing an interface class.and naming rulesExperimental results: As you can see, only one. class file is produced, the file name is the class name. Class
3, create the class CLASSC,observe the resulting. class file. The goal is to test for a. class file that is inherited from a parent class.and naming rulesExperimental results: As you can see, only one. class file is produced, the file name is the class name. Classmake a summary of the above 3 points:from the above 3 experiments, the resulting. class file is not related to the interface it implements, the inherited parent class, in which case it produces only one. class file, and the file name is the class name. class
4.creates a class CLASSD, defines a common inner class CLASSDD,observe the resulting. class file. The purpose is to test. class files and naming conventions that are generated in the case of internal classesExperimental Results:As you can see, 2. class files were produced, Classd.class and Classd$classdd.class. This indicates that the resulting. class file has a relationship to the inner class. The external class produces the same file as the 3 experimental results above, and is the class name. class, while the inner classes use theExternal class name $ internal class name. class, outer class, and inner class name separated by symbol $Note: The external classes here are relatively
5.Create Class CLASSD,defines a common inner class CLASSDD, and thenCLASSDD defines its inner classclassddd,observe the resulting. class file. The purpose is to test. class files and naming conventions that are generated in the case of internal classesExperimental results: As you can see, 3. class files were produced, Classd.class, Classd$classdd.class, Classd$classdd.class$ClassDdd. Class. The result is the same as the fourth experiment above, except that the 2nd-level inner class file adds its own class name based on the inner class of the 1th layer.
Note: The external classes here are relatively
 make a summary of the 4th and 5th experiments. all of the above two points are to verify which. class files and naming conventions are produced in common internal classes. Finally, the following conclusions are drawn:number of classes: see Defining the number of classes, including external classes and ordinary inner classesthe naming convention for the. class file name: The outer class name + $ + Internal class name +. Class, which is equal to the name overlay of the inner class of the layer and the outer class of each layer, but each class is separated by a symbol of $   6.creates a class Classe, defines an anonymous inner class,observe the resulting. class file. The purpose is to test. class files and naming conventions that are generated in the case of anonymous internal classesExperimental results: As you can see, 2. class files were produced, Classe.class and Classe$1.class. In fact, the result of this experiment is similar to the result of the 4th experiment, and the difference is that the inner class is represented by a number because it has no name.   This number is incremented once in the order of the defined anonymous inner classes. 7. Create class CLASSF and define another class in the same. java file CLASSFF,observe the resulting. class file. The purpose is to create a. class file that is the result of a class defined by the same. java file.Experimental Results:The. class file that is generated by the same. java file-defined class that conforms to the above-mentioned specification.
Final Summary: 1. Number of. class files generated after compilation: How many classes, how many. class Files 2,. class file naming rules:2.1 Common Inner class           External class name + $ + internal class name[+ $ + Inner classname + ...] +. class, separating the class name with the symbol $For example:Classd$Classdd$Classddd.class, here.CLASSDDD is the normal inner class of the underlying, its parent classCLASSDD, andThe parent class of CLASSDD is also the outermost outer classCLASSD2.2 Anonymous Inner class           External class name + $ + number[+ $ + Digital + ...] +. class, the class name is separated by a symbol of $, and the number is determined by the order defined in the outer categoryFor example: Classe$1$1.class 3, other non-public declared classes defined in the same. java file, follow the above 2-point specification 3, inheritance, or interface implementations, without affecting the number of. class files and naming conventions generated by the compilation.



From for notes (Wiz)



The naming rules for the class file generated after Java compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.