The 44th president has many things in common with the 35th. Barack Obama, like John Kennedy, was elected while still in his 40s after a short Senate career not marked by major legislative achievements. Both have attractive young families. Both campaigned as men who were cool and detached but also charismatic, attracting large cheering crowds and calling for change. Both also portrayed themselves as men who understood political differences and respected people with different views.

Most important, both were firsts — the first Catholic president and the first black president. Their elections 48 years apart broke barriers in American politics. Catholics cast 78 percent of their votes for Kennedy, according to Gallup, and blacks cast 95 percent for Obama, according to 2008 exit polls. Interestingly, since Catholics formed about twice as large a share of the electorate in 1960 as blacks did in 2008, Obama actually won a larger percentage of non-blacks than Kennedy did of non-Catholics.

Both faced spirited competition in the primaries from figures with arguably stronger claims on Democrats’ loyalties — Hubert Humphrey in 1960, Hillary Clinton in 2008. Both won key primaries against them — Kennedy in Wisconsin and West Virginia, Obama in the string of February contests. But neither would have won the nomination without the support of party insiders. Kennedy enjoyed endorsements from Democratic National Committee Chairman John Bailey of Connecticut, New York Mayor Robert Wagner and Richard J. Daley of Chicago. Obama lagged slightly behind Clinton in total primary vote, but got critical support from party activists in caucuses and from party superdelegates.

Kennedy was propelled into running by his millionaire father, the politically astute Joseph Kennedy, whose own politics were distinctly to the right of the party’s liberals. Obama scarcely ever saw his father, whose politics were much farther left than any American politician’s, though in Obama’s first autobiography he described his father as an inspiration.

As president, Kennedy remained cool and detached, and in his televised press conferences showed a wit and concision that struck viewers as charming and reassuring. His job approval remained up near 70 percent, far ahead of party lines, though it fell among white Southerners after he endorsed civil rights legislation. As president, Obama has been verbose in press conferences and polarizing in polls.

Kennedy’s victory went against the grain; the incumbent Republican administration was popular. That was decidedly not the case in 2008, and in retrospect, Obama’s win then was overdetermined.

The biggest differences between the two Democratic presidents are on policy. Kennedy sought to cut taxes, especially on high earners; Obama worked to raise them. Kennedy pursued a muscular foreign policy and increased defense spending; Obama has done something like the opposite.

There is a picture of the 17-year-old Bill Clinton shaking hands with Kennedy at the White House in 1963. There is no equivalent for Obama, a 2-year-old in Hawaii when Kennedy was assassinated a few months later.