If you declare it as
public class TestClass { public static String filePath="D:/Users/Mine/School/Java/CZ2002_Assignment/src/"; }
It will be available everywhere as TestClass.filePath
This may be useful (and your use case makes sense), but public static variables are a double-edged sword and cannot be overestimated to be able to access things that change from anywhere, as they can break encapsulation and make your program less understandably.
If the string is never changed for annother, you can add the final keyword, which will ensure that this never-changing behavior is executed, and also allow the JVM to make additional performance improvements (which you need not worry about)
Richard Tingle
source share