0

Possible Duplicate:
Compiler is creating extra class files with $ in them

I am using Netbeans to design a java app in which I am using Java Swing so apart from Java source files, I will have .form files which contains the description about the Java form.

In src diectory, I have 3 files like,

Downloader.java
DownloadCore.java
Downloader.form

Now, If I compile them manually using command prompt, (.i.e. without using Netbeans) then I am getting lot of .class files like,

DownloadCore.class
Downloader$1.class
Downloader$10.class
Downloader$11.class
Downloader$12$1.class
Downloader$12.class
Downloader$2.class
Downloader$3.class
Downloader$4.class
Downloader$5.class
Downloader$6.class
Downloader$7.class
Downloader$8.class
Downloader$9.class
Downloader.class

I am wondering why JVM creating this much of .class files, in which I have only 2 .java files, so it doesn't supposed to create 2 .class files alone. Why is it required?

Thanks in advance

Community
  • 1
  • 1
Dinesh
  • 16,014
  • 23
  • 80
  • 122

1 Answers1

5

Every class has its own .class files -- even anonymous ones. For instance:

// "top level" class -- in MyWhatever.java
public class MyWhatever {

    // anonymous class
    public static final Runnable anonymousRunnable = new Runnable() {
        @Override
        public void run() {
            System.out.println("I am an anonymous Runnable.");
        }
    }

}

This code snippet defines two classes -- MyWhatever and the anonymous class for anonymousRunnable. That second one will be called MyWhatever$1, which is what you're seeing. Each one of them will have its own .class file.

(By the way, it's not the JVM creating these class files -- it's the Java compiler, like javac or whatever Netbeans uses. The JVM then loads these class files and executes them.)

yshavit
  • 42,327
  • 7
  • 87
  • 124