Yes you can do that. See the documentation for the javac compiler, specifically the -target and the -source options.
Reason behind it? There are features in Java 1.5 code that earlier Java versions do not understand. Using the correct options when compiling creates bytecode that doesn't contain any "unknown" features. Of, course, you can't use any of the new features in your source code.