Correct

汉语 vs 中文

/ hànyǔ vs zhōngwén /
Strokes

Definition

汉语 and 中文 both are Nouns, which means [Chinese language; Chinese]/.

Example

汉语 means "the language of the Han nationality, i.e.Putonghua, the standard contemporary Chinese language". 中文 means "the Chinese language and script, in particular the language and script of the Han nationality".
1) In example ①, both words mean "the language of the Han nationality" and so are interchangeable. 中文 includes the written form of the language; to learn the Chinese language the learning of also includes the written form, hence there is no contradiction in between.

2) In example ②, 中文 means "the language and literature of the Han nationality". 中文系 is the customary name for the department of Chinese language and literature in a university. 汉语系 means the specialized studies of the Chinese language. Here, 中文 and 汉语 are not interchangeable.
1
dào
zhōngguó
中国
lái
xué
hàn
汉语
  
(
zhōngwén
中文
  
)
  

He came to China to learn Chinese.

2
zài
zhōngwén
中文系
xué
学习
xiàndài
现代
hàn
汉语
  

He is learning Modern Chinese in the Chinese Department.