James IV (17 March 1473 – 9 September 1513) was King of Scotland from 11 June 1488 until his death at the Battle of Flodden in 1513. He inherited the throne at the age of fifteen on the death of his father, James III, at the Battle of Sauchieburn, following a rebellion in which the younger James was the figurehead of the rebels. James IV is generally regarded as the most successful of the Stewart monarchs of Scotland. He was responsible for a major expansion of the Scottish royal navy, which included the founding of two royal dockyards and the acquisition or construction of 38 ships, including the Great Michael, the largest warship of its time.
James was a patron of the arts and took an active interest in the law, literature and science. With his patronage the printing press came to Scotland, the University of Aberdeen and the Royal College of Surgeons of Edinburgh were founded, and he commissioned the building of the Palace of Holyroodhouse and Falkland Palace. The Education Act 1496 passed by the Parliament of Scotland introduced compulsory schooling. During James's twenty-five-year reign, royal income doubled, the Crown exercised firm control over the Scottish church, and by 1493 had overcome the last independent Lord of the Isles. Relations with England improved with the Treaty of Perpetual Peace in 1502 and James's marriage to Margaret Tudor in 1503, which led to the Union of the Crowns in 1603.