There are two legal issues you need to be aware of..
One is copyright law. The other is patent law. Both cover software.
copyright law means that people can't copy your direct output. So for software, the SOURCE CODE and IMPLEMENTATION is covered by copyright law. If the book you wrote included source code along with it, then the book owner is most likely the source code owner. When you take somebody else's efforts and use them for yourself, you may be violating copyright laws. You can use somebody else's source code IF they have given permission. Often that permission may come with strings attached (like attribution, or only for non-commercial use, etc). Those issues are dealt with by copyright law. Copyright usually lasts a LONG TIME! (till death+80 years?). Copyright is "automatic". You don't HAVE to register anything to get covered by copyright law. Just proof you wrote it and when you wrote it, and you are covered.
Patent law is different. Software can OCCASIONALLY also be covered by patent laws. US Patent law covers "processes", although I don't think the EU and other countries has the same level of patent coverage for software. A Patent owner has a limited monopoly. This is often for less time (7-20 years?) depending on where and what type of patent it is. Patent law covers the actual process USED, not the source code itself. Hence a patent is much stronger, because it covers all "embodiments". You can't just re-write the source to get around a patent.
Although patent laws are a mess. Software patents are even worse. They are expensive to get. And often by the time they approved (3-4 years?) the idea has already been replaced. For example: Amazon has a patent on their "One Click" checkout. No other website can implement it without paying a royalty, unless they come up with a whole new novel and non-infringing method. Or they can wait till the patent expires.
Mostly I tell people, don't worry about patents too much, unless you are already a major corporation (and then just listen to your patent attorneys). People only sue you for patent infringement after you are widely successful. Mostly because they don't get approved until the product is already in the market for YEARS. Heck, when you do get sued for patent infringement, congratulate yourself, cause it means you are some sort of business success.