When you agree to develop software for a specific company, you will virtually always sign a contract with them. The contract should specify exactly what they expect you to deliver. Although your question amused your friend for some reason, the truth is that if you develop software under this sort of arrangement, the contract generally will include your delivering the source code, and ownership and copyright of that code will revert to the company. The deliverables will usually not include compilers, Java Virtual Machines, etc, because if you've just used standard, generally available things, the company will be able to get those by themselves.
Yes, that's possible, but it's not very common. If you are developing the software specifically for another company, they will almost always want a contract that gives them the source code. On the other hand, if you develop the software independently, and then afterwards sell the finished product to someone else, it's more possible that you might be able to give sell them only the executable. However even in this situations, many companies will not trust software without the source code, unless you (or more likely, your company) have a very good reputation for quality software and support. Even then, source code is frequently expected by customers. Trying to keep it from them will probably hurt your business, so I woulnd't do it unless there's a really compelling reason to do so. And given the possibility of decompiling Java programs, it's hard to imagine a really compelling reason.
As Prasanna said, you can deliver a technical minimum of some class files and tell the buyer he's on his own to set up a JVM and class path and so on to make it run. Getting some projects from SourceForge is about that primitive.
In a commercial product like a shrink wrapped box on a store shelf, users are likely to expect a lot more, like a nice installer that gets the latest JVM or provides the correct JVM, configures their personal preferences, sets up Windows icons to launch and more.
Several others talked about the "software for hire" world, where you should have a clear contract about what you should deliver and who owns what when you're done.
Are those the kinds of options you were thinking about?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi