James, the second surviving son of King Charles I and his wife, Henrietta Maria of France, was born at St James's Palace in London on 14 October 1633. Later that same year, he was baptised by William Laud, the Anglican Archbishop of Canterbury. He was educated by private tutors, along with his older brother, the future King Charles II, and the two sons of the Duke of Buckingham, George and Francis Villiers. At the age of three, James was appointed Lord High Admiral; the position was initially honorary, but would become a substantive office after the Restoration, when James was an adult.
He was designated Duke of York at birth, invested with the Order of the Garter in 1642, and formally created Duke of York in January 1644.
The King's disputes with the English Parliament grew into the English Civil War. James accompanied his father at the Battle of Edgehill, where he narrowly escaped capture by the Parliamentary army. He subsequently stayed in Oxford, the chief Royalist stronghold, where he was made a M.A. by the University on 1 November 1642 and served as colonel of a volunteer regiment of foot. When the city surrendered after the siege of Oxford in 1646, Parliamentary leaders ordered the Duke of York to be confined in St James's Palace. Disguised as a woman, he escaped from the Palace in 1648 with the help of Joseph Bampfield, and crossed the North Sea to The Hague.
When Charles I was executed by the rebels in 1649, monarchists proclaimed James's older brother king as Charles II of England. Charles II was recognised as king by the Parliament of Scotland and the Parliament of Ireland, and was crowned King of Scotland at Scone in 1651. Although he was proclaimed King in Jersey, Charles was unable to secure the crown of England and consequently fled to France and exile.
Exile in France
Turenne, James's commander in France
Like his brother, James sought refuge in France, serving in the French army under Turenne against the Fronde, and later against their Spanish allies. In the French army James had his first true experience of battle where, according to one observer, he "ventures himself and chargeth gallantly where anything is to be done". Turenne's favour led to James being given command of a captured Irish regiment in December 1652, and being appointed Lieutenant-General in 1654.
In the meantime, Charles was attempting to reclaim his throne, but France, although hosting the exiles, had allied itself with Oliver Cromwell. In 1656, Charles turned instead to Spain – an enemy of France – for support, and an alliance was made. In consequence, James was expelled from France and forced to leave Turenne's army. James quarrelled with his brother over the diplomatic choice of Spain over France. Exiled and poor, there was little that either Charles or James could do about the wider political situation, and James ultimately travelled to Bruges and (along with his younger brother, Henry) joined the Spanish army under Louis, Prince of Condé in Flanders, where he was given command as Captain-General of six regiments of British volunteers and fought against his former French comrades at the Battle of the Dunes.
During his service in the Spanish army, James became friendly with two Irish Catholic brothers in the Royalist entourage, Peter and Richard Talbot, and became somewhat estranged from his brother's Anglican advisers. In 1659, the French and Spanish made peace. James, doubtful of his brother's chances of regaining the throne, considered taking a Spanish offer to be an admiral in their navy. Ultimately, he declined the position; by the next year the situation in England had changed, and Charles II was proclaimed King.