Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

class names with "$"..

Thread view: 
Frances Del Rio - 14 Jun 2005 19:04 GMT
why do some classes have "$" in the names?  I have never seen this
before...  I just compiled some code I dl'd and form some source code
files I get three diff. classes with dollar signs...  for example for a
source code file called 'Connect.java' I get these three classes...

Connect$1.class
Connect$2.class
Connect$3.class

thank you....  Frances
TechBookReport - 14 Jun 2005 19:55 GMT
> why do some classes have "$" in the names?  I have never seen this
> before...  I just compiled some code I dl'd and form some source code
[quoted text clipped - 6 lines]
>
> thank you....  Frances

Your class contains anonymous inner classes, each of these compiles to its
own class file (numbered sequentially).

HTH
====================================================
TechBookReport Java        http://www.techbookreport.com/JavaIndex.html
Frances Del Rio - 14 Jun 2005 20:26 GMT
>>why do some classes have "$" in the names?  I have never seen this
>>before...  I just compiled some code I dl'd and form some source code
[quoted text clipped - 9 lines]
> Your class contains anonymous inner classes, each of these compiles to its
> own class file (numbered sequentially).

ok, still need to learn about inner classes, but thank you for your
response.....
Leon - 14 Jun 2005 22:00 GMT
[...]
> ok, still need to learn about inner classes, but thank you for your
> response.....
[...]

An inner class is a class within a class:

Class OuterClass {

   // Attributes and methodes

   Class InnerClass {

       // Attributes and methodes

   }
}

Greetings, Leon.
Frances Del Rio - 14 Jun 2005 22:34 GMT
> [...]
>
[quoted text clipped - 15 lines]
>     }
> }

thank you Leon..  so every time you have nested classes, when you
compile, the nested class becomes a class of its own?  this happens
every time you nest one class inside another? (except in a servlet, I
suppose (which of course is techn. a class......;).. I mean classes
inside a servlet are not techn. inner classes, right?)

(so here yr inner class has a diff. name from main class..  in my ex.
(taken from a real package w/a whole lot of classes) this comes from a
source code file called Connect.java, ran a search for word "class" in
it, I don't see any nested classes (no inner classes called "Connect" at
any rate..) thanks again, Leon...  Frances
Andrew McDonagh - 14 Jun 2005 23:12 GMT
>> [...]
>>
[quoted text clipped - 27 lines]
> it, I don't see any nested classes (no inner classes called "Connect" at
> any rate..) thanks again, Leon...  Frances

Leon's example is unfortunate that it described 'named' inner classes.
When compiled you should see the likes of

Outer$NamedInner.class

Whereas what you are seeing :

Connect$1.class
Connect$2.class
Connect$3.class

is the binary class files for 'anonymous' inner classes.

e.g.

public void someMethod() {

////////////////// This is the anonymous class...

  Runnable r = new Runnable() {

      public void run() {
        System.out.printLn("do something when called");
      }
   };

////////////

  r.run();

}

Runnable is an standard Java Interface, but anonymous classes can also
be derived from normal classes too in the same way as above.

Andrew
}
Leon - 15 Jun 2005 00:03 GMT
[...]
>>> An inner class is a class within a class:
>>>
[quoted text clipped - 8 lines]
>>>     }
>>> }

[...]

> Leon's example is unfortunate that it described 'named' inner classes. When
> compiled you should see the likes of
[quoted text clipped - 23 lines]
>
> ////////////
[...]

Understood. Thanks for explaining..

Greetings, Leon
Juha Laiho - 17 Jun 2005 21:20 GMT
Frances Del Rio <fdr58@yahoo.com> said:
>> An inner class is a class within a class:
>>
[quoted text clipped - 14 lines]
>suppose (which of course is techn. a class......;).. I mean classes
>inside a servlet are not techn. inner classes, right?)

It's not often when you see inner classes in a servlet. Note the
construct above; there's the top-level class declaration (class OuterClass),
and completely nested within it another (class InnerClass).

When you write a servlet, you pretty much have

public class MyServlet extends HttpServlet {
// ... variables and methods for MyServlet
}

Of course, there's no restriction why you couldn't have inner classes
within servlets, but I think that'd rather often indicate that there's
too much processing logic in the servlet (instead of decoupling the
logic to a set of generic classes, and only using servlets to create
a web interface for the logic).
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

Tor Iver Wilhelmsen - 18 Jun 2005 12:51 GMT
> public class MyServlet extends HttpServlet {
> // ... variables and methods for MyServlet
> }

Well, usually just methods. Putting state in a servlet - especially
state related to requests - is evil. State belongs in request, session
or application scope explicit, not in any servlet class variables.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.