File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Real time application of Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Real time application of Inner Class" Watch "Real time application of Inner Class" New topic
Author

Real time application of Inner Class

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
Hi all,
i need a real time application or implementation to understand the property of inner class. i read and got the semantics of inner class by using MyOuterClass and MyInnerClass. But i need some real time scenario where we can implement Inner Class to represent that Entity.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

Do you mean "real time" as in real-time computing or "real world", meaning a concrete example?
If you mean the latter, I once used an inner class to implement a linked list. Linked lists are made up of node which contain a data reference and pointers to other nodes in the list. Since the user of the linked list is interested in the data in the list and not the implementation of the list itself, I made the node class an inner class.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi joe i am meant to say real world.

can i say that the output of certain process will be a member of the outer class and the thing or logic which brings out will be a inner class..
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

You can declare anything to be an inner class. The question remains: should it BE an inner class? I think you have to clear up the relationship between your classes before you can answer that. Have a look at the Java Tutorial chapter on Nested Classes for some more examples.
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
You would use an inner class only if you are dealing with an object that has no use or meaning outside of its outer class and is complex enough to merit its own objectification (for a lack of a better term). It's difficult to find a general example because it really depends on your application, but perhaps an Address class could have a PhoneNumbers inner class which holds all the phone numbers associated with the address and implements some extra functionality, like returning the best phone number, the most used one and whether they are all in the same area code. You need a class to do all the extra nifty things, but you don't really need it in a separate class, since you do not need (or want) to deal with phone numbers outside of the context of an Address.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Real time application of Inner Class
 
Similar Threads
about inner class
Example and use of Anonymous Inner Class in j2ee projects.
in what situations we will use anonymous class
Reg Inner Class
Help with inner classes.