I had installed joomla in my domain with the sample data. I now removed it and installed wordpress in my domain. There are a lot of 404 errors in my domain. Will they affect my search engine rankings. If so what should I do to avoid it?
Google just wrote a blog post that should answer your question very well
Q: Do the 404 errors reported in Webmaster Tools affect my site’s ranking?
A: 404s are a perfectly normal part of the web; the Internet is always changing, new content is born, old content dies, and when it dies it (ideally) returns a 404 HTTP response code. Search engines are aware of this; we have 404 errors on our own sites, as you can see above, and we find them all over the web. In fact, we actually prefer that, when you get rid of a page on your site, you make sure that it returns a proper 404 or 410 response code (rather than a “soft 404”). Keep in mind that in order for our crawler to see the HTTP response code of a URL, it has to be able to crawl that URL—if the URL is blocked by your robots.txt file we won’t be able to crawl it and see its response code. The fact that some URLs on your site no longer exist / return 404s does not affect how your site’s other URLs (the ones that return 200 (Successful)) perform in our search results.
Check my answer here. It's for 403 pages but it does the job in your case, too.
PS: good choice to choose WordPress over Joomla!.
I just wanted to add my experience. Last March, I started a website and it was steadily moving up the serps. One day, it disappeared completely. I did everything I could think of to try to bring it back. I added fresh content and more backlinks but nothing worked. A month later, I decided to log into my webmaster account to see what was up (I forgot I had set up a webmaster account for this site). I found a ton of 404 errors. I immediately went to work cleaning them up. A couple days later, my site was back in the serps. I do think that 404 errors can and does affect search engine rankings.
I've got another site that disappeared from the serps on Jan 13. I couldn't understand why because, on that same day, I decided to add some new content to the site and that usually causes the site to move up in the serps, even for a day or two. Today, I decide to log into my webmaster account (I should do this more often) and I found ten 404 errors discovered on Jan 13 - the same day the website disappeared from the serps. I fixed the errors and I bet in a few days, the site will have it's search rankings back.
There is no clear argument how error 404 can affect your site ranking, the truth is that while error 404 may not affect your site's ranking it could affect user experience on your site, and yes in a way or the other it can affect your site ranking.
Sure If a page has an outgoing like for 404 page then search engine will add an negative point to it. So automatically SERP for the result will reduce.
Yes it surely effects site ranking and its indexing if there are many 404 errors it is advisable to check the health section of Webmaster Tools in Google and try to fix up the issue for better ranking and visibility of website.