This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Dumb question about how javac names files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dumb question about how javac names files" Watch "Dumb question about how javac names files" New topic
Author

Dumb question about how javac names files

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659
    
  11

So I understand that the compiler takes *.java files, processes them and spits out *.class files.

But, when there's more than one class in a file, what's the deal with making multiple *.class files with a "$1" in the middle?

Does this mean I should be using more than one *.java file? Is the compiler (only slightly joking here) mad at me and fixing my mistakes??

This situation is for class files for button listeners -- the classes are inside the GUI java file. I wanna do the right thing and not learn things by doing it wrong.

/Janeice/


When you do things right, people won't be sure you've done anything at all.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's just how Java handles inner classes.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659
    
  11

Are inner classes "sloppy"?

I mean, should I make new classes for these action listeners?

Thanks....
Janeice
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

"Should" implies a level of obligation I'm uncomfortable with in this situation.

(Sorry, it's a pet phrase of mine.)

See my response to your other thread.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Janeice DelVecchio wrote:Are inner classes "sloppy"?

Only when used sloppily.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Inner classes are quite often very useful. Anonymous inner classes are great for when you need a class only at one specific point in your code. Event listeners are quite often programmed as anonymous inner classes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
The only problem about anonymous inner classes is that bit Rob mentioned about "one specific point". It can be difficult to be sure you won't need something similar elsewhere. If I am sure there is only one place I shall use it, I am happy to use an anonymous inner class.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659
    
  11

Thanks!!

--Janeice
 
wood burning stoves
 
subject: Dumb question about how javac names files
 
Similar Threads
One Public Class Per Source File?
Code problem or logic problem ?
Class and inner class declarations
ClassNames
why won't this compile?