Is it enough to just have faith in God? Or do you have to have something else for salvation? These questions have been asked for ages and debated by many men that are much smarter than I, and much of that debate has been centered around this seemingly contradictory passage. All that I can do is try my best to wrestle them out in a way that makes a bit of sense and see what I find about the nature of God.
It seems clear that faith is the only critical component of salvation, but this passage indicates that even the demons believe in God. We have to remember the definition of faith, from "Hebrews," to catch the subtlety of the wording. Belief is simply knowing that something is true. Faith is knowing that it's true and having a personal interest in it. Remember that faith has a component of hope tied to it. The demons know that God exists and the Jesus is His son, but they do not have any hope that they can be saved therefore they have no faith. They have no ability to transmute their belief into faith as we do.
Given that, then we see that this passage does not necessarily contradictory with the doctrine of salvation by faith, but it does still have a focus on works that we don't really find in most of the New Testament. Paul was all about preaching freedom from the Law and how you can't fulfill the Law and earn your way to heaven, but it seems, on the surface, that James is preaching that works are integral part of salvation. How can they be saying the same thing?
Paul preached salvation. Paul taught people that had never heard the gospel how to start a relationship with God, and that relationship starts with faith. There is nothing more to it. You can't work your way into a relationship with God. You either have faith or you don't.
James is preaching growth. James is speaking to all of the believers. His audience already has a relationship with God. They already have faith. James is pushing them to the next step, and the next step is works.
The works don't make a difference in whether or not you are a Christian. They are simply the next thing that happens. When you have genuine faith and a relationship with God, you are going to have good works. Paul says the exact same thing in "Galatians" when he talks about the fruit of the spirit. The fruits of the spirit are produced when the spirit is in you. You don't really have to try to produce it; it's just there. The same is true of a Christian's good works.
The evidence of a healthy relationship with God and a healthy faith is good works. If someone were to say that they were a strong, mature Christian and they didn't demonstrate that with good works, then that is an indicator that they are at least deceived in their walk and could be an indicator that they are not even genuine in their faith. We are warned over and over again to be careful to not allow false teachers into our churches, and we need a mechanism for identifying them. We can't see a man's heart to know for certain the condition of their faith and relationship with God, so God has given us a litmus test of sorts. A healthy mature relationship with God generates the fruit of the spirit and good works.
We can't use this as the end all test because there are plenty of people in this world that do good works without any relationship with God, and there are plenty of people that have a relationship with God that we may not observe doing good works for whatever reason. So don't replace building relationships with others and testing the doctrine of their teachings with this simple test. If you do, then you risk becoming the superficial judge that James warns about in the first part of the chapter. Mostly, use this for yourself. What does my relationship with God look like? Am I producing fruit of the spirit? Am I compelled to do good works? When those things happen on their own, then you on the right track in your spiritual growth.