I need my Java program to have two display modes: a GUI interface and a command line interface. If I run it in Windows, OS X, or another graphical environment I should get
Both dacwe and vitaut are right. I just wanted to add one recommendation. You should use MVC (model-view-controller) pattern when you are designing your application. So, if it is running in UI mode it uses UIView, otherwise the ConsoleView.
Dacwe recommended you how can you decide automatically which mode to use. Due to Java is cross platform language I think the name is operating system is irrelevant for you. The fact that the system has graphic environment is more relevant, so use GraphicsEnvironment.isHeadless()
.
System.console()
will help you to create shell controlled application.