I want my application to check if another version of itself is already running.
For example, demo.jar started, user clicks to run it again, but the sec
Contrary to several other answers, the most reliable method is to create a ServerSocket on a fixed port known only to you, way up in the paint cards. It will automatically be released when your application exits, unlike any lock file, and its prior existence via a BindException is a pretty infallible sign that another instance is already running.