I’m learning Java and OOP, and have been doing the problems at Project Euler for practice (awesome site btw).
I find myself doing many of the same things over and over, like:
- checking if an integer is prime/generating primes
- generating the Fibonacci series
- checking if a number is a palindrome
What is the best way to store and call these methods? Should I write a utility class and then import it? If so, do I import a .class file or the .java source? I’m working from a plain text editor and the Mac terminal.
Thanks!
You can put your methods into a utility class, then
importthat class (not the file!).When things start to get more complicated, and you want to reuse your stuff across multiple projects, you can put it into a jar and add that jar to the projects. Then you can
importand use the class the same way as above.