When visiting Barcelona, you will find two official languages there: Catalan (català) and Spanish/Castilian (castellano). This may surprise you, but Spain has in total 4 official languages, the two others being: Galician (gallego) and Basque (Vasco).
Catalan and Castilian/Spanish are two well defined languages with a long history. Both are official languages not only in Barcelona, but in the rest of Catalonia and also in Valencia, part of Southern France and the Balearic Island (see below).
In Barcelona you will find Catalan language to be more dominating than Castilian/Spanish. This is a fact that often surprises the foreign visitors.
They come to Barcelona with an idea that people only speak Spanish, but they get themselves a surprise, since they encounter a language not easily understood by a Spanish-speaking without prior studies. This also means that many foreign students come to Barcelona to study at the university without knowing that some or many classes will be in Catalan. To them it is a big surprise to encounter a language they are not familiar with. It can be frustrating for them to try to keep track of what is said in classes and to read the books for classes.