Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simulating Pointers in Java...

Posted on 2005-03-24
4
Medium Priority
?
526 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
  • 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

Technology Partners: 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

564 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