Are we saved by grace or works?
Ephesians 2:8,9; Romans 3:20,28; Galatians 2:16
and James 2:24; Matthew 19:16-21
God does not want a faith that is empty and hypocritical. James 2 is talking about those who "say" that they have faith but have no works. Therefore, people cannot tell if they are true believers or not, because there is no fruit. That kind of a faith is useless and is not a saving faith. True faith results in true works.
In Matthew 19:16-17, Jesus was speaking to a Lawyer who was self-righteous since he wanted to put Jesus to the test (Luke 10:25). He asked what he must do in order to obtain eternal life and Jesus responded with the requirements of keeping the commandments. If a person keeps all of the commandments, it would seem that they could obtain eternal life. However, nobody can keep all of the commandments. Therefore, Jesus' comments to this man show this man that justification can only be by faith since no one can keep all of the commandments. This is why it says in Eph. 2:8 that we are saved by grace through faith. Also, Romans 3:20,28 and Galatians 2:16 tells us that no one is justified in the sight of God by the law; that is, by the works that he can do.
There is no contradiction at all when we examine the contexts. We are justified by faith but that faith must be alive (James 2). The Law cannot save us because we are incapable of keeping it (Matthew 19:16-17). Therefore, salvation is by grace through faith.
For more information, please see the paper Are we Justified by Faith (Romans) or by Works (James)?