First of all, one doesn't "write a book in PDF format." PDFs aren't generally made to be editable at that level. It can be done in theory, but practically you'll be creating your document in another program/format like Word, OpenOffice, TeX, DocBook, or HTML then converting it to PDF later.
The bookmarks and TOC are going to be dependent on the application that you write your document in, and how it gets converted to a PDF.
If your source document has a TOC that's linked to the destinations within the document and you use some sort of PDF export that knows how to use that information, then it can create a PDF with your TOC linked internally.
For example, if you use Word, and create a TOC in your doc that works, then use it's native Save As PDF feature (or Acrobat's PDF Maker, or PDF-T-Maker), then it will create all those bookmarks for you.
If you're using Notepad and PDFCreator to "Print to PDF", it's not going to work.
Other file types depend on how they get converted to PDF. Acrobat can take HTML pages (websites) and build the bookmarks.