I use method A in several different Java projects. Is there a way to write the method just once and then call it as required from different Java projects?
2 Answers
Yes. Define public class and define at least public or protected method. Then import that class in your new project's class and use it.
default classes with public or protected methods are not accessible in different projects/packages even if default class' methods are public/protected.
So use public class and public or protected methods and at last create a jar with this file and add this jar file in your project to use.