I have a class that I use to do certain calculations.it has some methods thatare called by other classes to do stuff like pick a random letter.now my question is how can I make this as fast as posibble.

lets call this object "calc"

should I create a local instance of this "calc" object every time I want to use one of its methods?

or should I create this "calc" once in every object that uses calc and then use that link to call a method?

should I create a local instance of this "calc" object every time I want to use one of its methods?

No, I wouldn't. Otherwise you're going to end up with lots of 'calc' objects being created, abandoned and GC'd. It's generally a good idea to avoid creating new objects where possible; particularly if you are doing it in frequently called methods or loops.

If it's already heavily used in this way throughout your code, then perhaps you could leave it??? In theory you're not going to gain blistering increases in performance by changing it. But for your future reference keep in mind that utility classes like this are very suited to being static (take java.lang.Math as an example).

*Just to add: It looks like you've made a utility class that will be re-used in other programs? In this case, yes I'd change your methods to static. You should be able to do this without breaking your current code that uses objects.

your methods tell me that you are quite new to programming and Java. You duplicate a lot of code which is either present already in the standard library or doing stuff which is extremely unperformant or code size.

Hey, you need to clean up your code. (Or at least make the same mistakes consistantly). You sometimes use camel case and then other times you dont. I recomend never starting a method off with a capital letter, that implys that it is a constructor, which it isnt.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org