I am relatively new to java programming and i am having troubles with my client - server code

I want to implement commands such as
#quit causes the server to quit gracefully

I want to implement this using the user of the server.
How do I get the user input and test it to make sure it is the correct input and then call a method to cause the server to quit?
Also, where do i put this code, on the server side or on the user of the server side?

Any help would be appreciated, examples would be great

Thank you