Having not yet reached the age of 14, Fontes joined the Portuguese Royal Naval Academy in the midst of the civil war between absolutists and liberals. Two months later, in October 1833, during the siege of Lisbon by absolutist forces, the young cadet took part in the successful defence of the city led by Napier. In the following three years, he pursued his midshipman training, excelling in mathematics. He graduated in 1837, receiving a prize for students of exceptional merit that had only been awarded twice in twenty years.