Storing Vs. Generating Strings
<p>after being a faithful user of Stackoverflow for a number of years, I've finally decided to write my own question, so I apologize if I've missed something.</p>

<p>I tried searching for this topic, but wasn't entirely sure how to word it.</p>

<p>I am programming in Java, and am writing a plugin for a Minecraft server.  I want to make this plugin responsive to user input, so I'm sending a great variety of messages to players, including success messages, help messages, errors, etc. Sending a message to a player can be achieved through a simple method in the player object: <code>player.sendMessage(String message);</code></p>

<p>However, I don't want to simply use that method to directly send the message in every instance, but rather I'd prefer to store all the messages in one location, in order to make the code easier to manage in the event of a typo or a decision to change the text.</p>

<p>My current implementation of this is a class called Messenger.  For each message that can be sent to players, it contains a public void method that accepts a player as an argument, as well as specific information relative to the message, in order for it to be highlighted and included in the message.</p>

<p>A hypothetical example would look like this:</p>

<pre><code>public void playerPosition(Player player, int x, int y, int z) {
    player.sendMessage("Your coordinates are: "+x+", "+y+", "+z+".");
}
</code></pre>

<p>However, I'm still new to Java and am doing my best to implement best practices and efficient designs.  I know there's a better way to handle this situation and maintain a high level of readability and maintainability.</p>

<p>These methods would be static, as I read that static methods have a smaller memory footprint, but some of them reference non-static variables in the Messenger class, in order to convey some dynamic information from other sources to the player.</p>

<p>I'm going to rework that so that all the information needed will be passed directly to the methods, so they can be static.</p>

<p>However, I got to wondering: Is it more efficient to generate the results of the message every time the method is called, or should I store the content of the message in a string and simply return that string?  Is the compiled code of a method faster and more efficient than returning a stored string?</p>

<p>If returning a stored string were faster, I could simply store the string with argument placeholders for later use by String.format();</p>

<p>I hope this wasn't too lengthy for my ultimate question, but I hope that I might also be led in the paths of programming righteousness in regards to my approach as well.  That said, if you see something I should do differently, or indications of a fundamental misunderstanding I might be experiencing, please, let me know!  You're all great, thanks!</p>