JAVA thong into a separate class


I'm trying to put all String into a separate public class, the compiler is against it, how can I persuade him? My texts for the user are quite long, if they are removed from the main class, then the code will not be overloaded with unnecessary text and become more readable?

public static void main(String[] args){

public class stingsStore{
String hello = "Здравствуйте дорогие друзья";
String w_up = "Очень рад, бла-бла-бла. Как поживаете?";
String bye = "Ну всё пока, потом ещё куча текста...";

Thank you.


Use standard Java Properties. Put all your strings with some kind of keys in the file and then use the ResourceBundle to get the value of the string given the key. For example, having:

hello = Здравствуйте дорогие друзья
w_up = Очень рад, бла-бла-бла. Как поживаете?
bye = Ну всё пока, потом ещё куча текста...

To get the 'hello' string

String basename = "messages";

Of course, this solution looks more complicated than string constants, but it allows you to separate the content of the texts from the code, and you can then translate the strings into another language when you enter the international market. Yes, still, properties support multiline data.

Scroll to Top