Register now or log in to join your professional community.
No ... there are no global variable allowed in Java
In addition to the other answer, you should also consider System.setProperty() and System.getProperty(), though I personally wouldn't go for this option if there are more than very few variables.
In case there are several global variables, use the method suggested in the other answer if they are never changed.
But if the variables are subject to change (not programmatically), I suggest you use a properties file which the GlobalClass reads from. This would prevent rebuilding your application when the values have to be changed.
Global Variable in java be on Level of Class only
and to define variable global you can use it in any position of Your Application you Define Variable as Static and you can access it from any position.
Example :-
publicclassGlobalClass{publicstaticint age;publicstaticstring name;}GlobalClass.age;GlobalClass.name;