Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Share objects in a standalone java application

 
Janelle Goldsmith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I am fairly new to Java and want to know all the possible mecahnisms to share objects in a standalone java application.
Thanks
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

... all the possible mecahnisms to share objects in a standalone java application.

I doubt that they've all been tried. All objects are unique (one of the core principles of Object Orientation) and can be shared among any other object in a variety of ways. They can be passed as parameters in methods, they can be returned from methods, they can be referenced directly as fields, they can be members of collections, etc. The thing to remember in Java though is that objects can only be accessed by a reference. Objects can become orphaned when there are no longer any reference that refer to them. When that happens they become subject to garbage collection.
Michael Morris
[ March 20, 2003: Message edited by: Michael Morris ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and then there's all those funny persistence strategies.
Welcome to JavaRach, Janelle! What are you trying to accomplish?
 
Janelle Goldsmith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the welcome.
I heard about storing the objects in persistent storage like files etc.
When would that be used in a standalone java application ?
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I heard about storing the objects in persistent storage like files etc.
When would that be used in a standalone java application ?

Whenever you need to store and retreive the state of the object. For example, your program monitors the stock market activity during the trading day. After the trading day, you can close your app. When you restart it the next day, your program will restore its state and resume execution.
Eugene.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic