Can Firewalls really prevent Virus and Trojan attacks

With most of the things getting digitalized, there is no second opinion that people are dependent on internet to do different things. Be it using for personal purpose or for official purpose, internet has gained immense acceptance in our lives. Smart phones and computers have become an indispensable part of life but it is very necessary to keep the devices secure from viruses and cyber attacks.