In this article it is stated that:
The JDK includes two flavors of the VM — a client-side offering, and a VM tuned for server applications. These two solutions share the Java HotSpot runtime environment code base, but use different compilers that are suited to the distinctly unique performance characteristics of clients and servers. These differences include the compilation inlining policy and heap defaults.
The JDK contains both of the these systems in the distribution, so developers can choose which system they want by specifying -client or -server.
Although the Server and the Client VMs are similar, the Server VM has been specially tuned to maximize peak operating speed. It is intended for executing long-running server applications, which need the fastest possible operating speed more than a fast start-up time or smaller runtime memory footprint.
The Client VM compiler serves as an upgrade for both the Classic VM and the just-in-time (JIT) compilers used by previous versions of the JDK. The Client VM offers improved run time performance for applications and applets. The Java HotSpot Client VM has been specially tuned to reduce application start-up time and memory footprint, making it particularly well suited for client environments. In general, the client system is better for GUIs.
Does this mean that if one wants to run an application with the -server flag, one has to compile with a certain mode to get it to work properly?
No, this is a runtime setting. The bytecode for your application is identical. You use this flag when you start the JVM.
The confusion probably comes from the fact that “compilation” also takes place at runtime, because the JVM does JIT (just-in-time) compilation of Java byte code to native machine code (and how that is done is affected by this flag).