I suppose you must be using some sort of
IDE like eclipse of Netbeans or any IDE. All IDEs provide you the feature to choose the build compiler version.
For netbeans, Open Project Properties and do as is shown in the image :-
Here you can add different Platform for your project and choose to compile your project using that version of
Java. Similar options you will find in eclipse and IntelliJ as well.
Hope that helps
Thank you,
Sincerely,
Psycho_Coder.