This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Packaging Classes Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Packaging Classes Question" Watch "Packaging Classes Question" New topic

Packaging Classes Question

Cyrus Serrano
Ranch Hand

Joined: Sep 29, 2003
Posts: 137
Hello all,

just wondering, when i tried to compile a class that has a package statement, it generates 2 class files. For example my source file name is :, after compilation it will generate:

Form1.class and Form$1.class

Why is there an extra class file with a dollar sign....
Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
Hi it's not because you have the the file in a package. You get two files when you have created a source file with an inner class, When you create a class with an inner class, two files will be created when you compile the source file the inner class being the one with the dollar sign.

Martyn...<br /> <br />SCJP 1.4 SCWCD 1.4
Cyrus Serrano
Ranch Hand

Joined: Sep 29, 2003
Posts: 137
thank you for the reply, but there are no inner classes in my program, here is a code snippet of one of my class files:

package com.StiCalJava.event;

import java.awt.*;
import java.awt.event.*;

public class Form2 extends Frame
public Form2(String str)
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)


it thus, generate 2 class files Form2.class and Form2$1.class
Is there an inner class in my program.. thanks
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Your code contains an anonymous inner class, which is derived from WindowAdapter.

Note that the class file is $1 because the inner class is anonymous. If you had a named inner class it would be $NameOfInnerClass.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: Packaging Classes Question
jQuery in Action, 3rd edition