What is nationalism? What is the nature of nationalism? What's objective and what is subjective part of it?
Very deep, old, and so far under-resolved question continuing to occupy the minds of intellectuals and scientific world. There is a heck of a lot of books and theories made on this theme.
In my humble opinion, It's a sort of religion, psychological phenomenon, the end result of which is a mass identity replacement. Many people do have a 'damaged identity' and the morbid anxieties related thereto. But when those people unify themselves under the flag of some similarities (even if those similarities are completely ephemeral or trivial) they feel some kind of relief of the pain, created before by the identity vacuum. It is like a club of people who were born on Monday and who pride themselves on this fact, ascribing to Monday some 'special' even mystical (religious) qualities.
The anger and potential war (in broad sense: war of words, war of trade, military war in extreme cases) with those belonging to 'other world' is one more major way of venting the identity deficit anxiety. As with all self-fulfilling forecasts, the state of war with 'bad others' allegedly threatening their special national belonging, is, in the eyes of nationalists, one more evidence that they are really 'special and different', and, hence, do have a fairly firm identity.
All of this doesn't mean, that the degree and activity of nationalism cannot be controlled or 'activated'. There are more and less acute forms, and even, what could be called 'sleeping or latent nationalism'
Historically, nationalism began really strong and really felt in earnest only from the end of 18th - beginning of 19th century. Then the Governments got the real power over their nation-states and learned how to exploit and even create this identity-crisis. The very term 'nation-state' was invented by European politicians as demagogic conception (let many pundits disagree with me on this one) to legitimize their political power sharing and power holding over multitudes of people. Nationalism became an ideological weapon of mass destruction, a perfect masterpiece of demagogy - super-duper socio-psychological medication, allowing Governments to hold power and to gain those ends, which before they could have gained only with the help of the direct force against their own peoples. Of course that's not to say that they (politicians in power) themselves did not get sucked in the self-induced ideological whirlpool of nationalism: of course it was flattering and pleasant for their ego to 'realize' that they were kind of heroes and good helpers who were 'kindly asked' by their respective 'nations' to rule over them, as if those nation were single subjects with a single will. Of course this self-reflection was 'just what the doctor ordered' for those powerful people in authority - such conception would help even the most hard-headed politicians, sending thousands upon thousands of people to war and death, to sleep tight and well (though even before those ruling elites had not suffered too much from a bad sleep). Needless to say, this concept of state-nation was 'nationally relativistic' and politically conveniently split the moral (what is bad in general could be good if France or Germany needs it; what is bad for England and her people could be good and ethically justified for Russia etc - regional fragmented moral, that serves not the universal ideals of the Enlightenment, but 'nations' and in practice the political elites of those 'nations')
So nationalism in the shape we know it now was to a large degree an invention, a lever developed, improved and 'polished' by the political power after the so called nation-states were created and the means of controlled mass communication and broadcasting were developed. So now we more often than not deal with an artificially induced 'boosted' nationalism (in overdrive mode), 'genetically modified nationalism'.
But the fundamental causes of it lie in the identity crisis and the venting of the relevant anxieties and psychological pain.