I just learnt basic networking. If I have 2 departments which I do not want them to access each other's networks, does using two layer 2 switches connecting to the router does the job or do I need a layer 3 main switch with vLan ----> two layer 2 switches to do the job?
The answer really depends on the capabilities of your switches. If you have a single managed switch that can be configured with VLANs (almost every enterprise-grade switch ever made), then you can set up different VLANs, which logically divide the switch as if you had separate switches.
To get traffic from one VLAN to another VLAN requires a router, and you can then place access lists on the router VLAN interfaces to prevent traffic between the VLANs in the router. A router would normally automatically route traffic between the VLANs, or even two separate connected switches, but you can place layer-3 security to prevent that or restrict it to certain addresses or traffic types.