?
Solved

Simulating Pointers in Java...

Posted on 2005-03-24
4
Medium Priority
?
519 Views
Last Modified: 2012-06-27
Ok, this is a relatively simple question from a C++ addict that's spent far too long cussing at Java for not being quite so flexible as C/C++ when it comes to pointers etc. So, I'm basically asking what would be the 'standard JAVA method' of overcoming this problem...

I have my class (PendulatorFrame) which contains details of the main window frame, and in this class, is another class which stores information about a dynamical system (PendulatorSystem). I then want to have 2 other classes in PendulatorFrame that are 'viewports' for the dynamical system. However, I need these viewports (which extend Component) to access the PendulatorSystem that lives in PendulatorFrame directly. I would normally do this in C++ by storing a pointer to PendulatorSystem in PendulatorViewport2D and PendulatorViewport3D, but obviously, Java doesn't understand pointers, and I believe that if I were to have an instance of PendulatorSystem defined in PendulatorViewport2D and set that 'equal' to the one in PendulatorFrame when it's constructed - it will merely be another instance which starts off the same (and so, when the one in PendulatorFrame advances, the one in PendulatorViewport2D DOESN'T).

If someone could clarify the 'standard Java way' of handling this lack of pointers, that would be greatly appreaciated.
0
Comment
Question by:Telumehtar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 600 total points
ID: 13625545
> it will merely be another instance which starts off the same

that is not correct, both vars will point to the same instance (as u require)
0
 
LVL 2

Author Comment

by:Telumehtar
ID: 13625597
Really - So Java doesn't pass values, but a reference?

So I could pass the same PendulatorSystem to a completely seperate class (buttonListenerHandler) and it would also be able to directly access this variable?
0
 
LVL 2

Author Comment

by:Telumehtar
ID: 13625665
Would you believe it - you're right. It's easy points day for objects today!

Sorry for the stupid question, I just didn't want to mess up the 500+ lines of code I have by putting in a whole bunch of new prefixes to all the variables if it wasn't going to work.

Many thanks!
0
 
LVL 92

Expert Comment

by:objects
ID: 13625691
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question