How did Gandalf know?
In a section of Unfinished Tales called "The Quest of Erebor", Gimli asks Gandalf this very question. Here is the response he gets:
Gandalf did not answer at once. He stood up, and looked out of the window, west, seawards; and the sun was then setting, and a glow was in his face. He stood so a long while silent. But at last he turned to Gimli and said: 'I do not know the answer. For I have changed since those days, and I am no longer trammelled by the burden of Middle-earth as I was then. In those days I should have answered you with words like those I used to Frodo, only last year in the spring. Only last year! But such measures are meaningless. In that far distant time I said to a small and frightened Hobbit: Bilbo was meant to find the Ring, and not by its maker, and you therefore were meant to bear it. And I might have added: and I was meant to guide you both to those points.
'To do that I used in my waking mind only such means as were allowed to me, doing what lay to my hand according to such reasons as I had. But what I knew in my heart, or knew before I stepped on these grey shores: that is another matter. Olórin I was in the West that is forgotten, and only to those who are there shall I speak openly.'
Death knoll for Java
So, this is the hill which Java chose to die on? <ducks and runs>
I am not at all happy about the title 'the Two Towers'. It must if there is any real reference in it to Vol II refer to Orthanc and the Tower of Cirith Ungol. But since there is so much made of the basic opposition of the Dark Tower and Minas Tirith, that seems very misleading. There is, of course, actually no real connecting link between Books III and IV, when cut off and presented separately as a volume.