java compiled classes contain dollar signs

Inner classes, if any present in your class, will be compiled and the class file will be ClassName$InnerClassName. In case of Anonymous inner classes, it will appear as numbers. Size of the Class (Java Code) doesn't lead to generation of multiple classes.

E.g. given this piece of code:

public class TestInnerOuterClass {
    class TestInnerChild{

    }

    Serializable annoymousTest = new Serializable() {
    };
}

Classes which will be generated will be:

  1. TestInnerOuterClass.class
  2. TestInnerOuterClass$TestInnerChild.class
  3. TestInnerOuterCasss$1.class

Update:

Using anonymous class is not considered a bad practice ,it just depends on the usage.

Check this discussion on SO


This is because you have anonymous classes within this larger class. They get compiled using this naming convention.

See The Anonymous Class Conundrum


In addition to the above cases presented by @mprabhat, the other cases could be:

  1. if you class contain a enum variable a separate class would be generated for that too. The name of the .class generated would be ClassName$Name_of_enum.
  2. If your class X is inheriting i.e. extending another class Y, then there would be a .class generated with the name ClassName$1.class or ClassName$1$1.class
  3. If your class X is implementing an interface Y, then there would be a .class generated with the name ClassName$1.class or ClassName$1$1.class.

These cases are derivations of my inspection on .class files in jar.