This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Passing data back and forth between classes  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to understand how to pass data gathered in one .java file to another.java file.
For instance, I ask a user for their name and age. The I want to send the name and agae variable to another .java file to compute their birth day by subtracting their age from the current year. I then want to send the data bak to the first .java file to output the birth year.
I know I need to use instantiation, but I don't know where or how.
Any help would be appreciated.
Thanks.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,
You will understand better if you look at this tutorial :
http://java.sun.com/docs/books/tutorial/
Susilo
 
Author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to use two different classes to solve this problem? Is this an assignment?
 
Jeff Koch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is in reference to a assignment. My specific example is not part of the assignment but just the type of assignment.
I essentially as supposed to pass data from one .java file to another. THe variables have to be gathhered in the first file and computed in the second?
THanks.
 
Jeff Koch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THe tutorial was good but not much help. Any other suggestions?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't know the answer, I just played around with this - using the constructors to pass info - and it seems to work OK, but I don't know if there are any pitfalls doing it this way
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!