True and obedience which "follows" real faith led by the Holy Spirit and is produced "out of" faith is works. (Ephesians 2:8-10)
In James 2:14, we read of one who says/claims (key word) he has faith but has no works (to evidence his claim). That is not genuine faith, but a bare profession of faith. So, when James asks, "Can that faith save him?" he is saying nothing against genuine faith, but only against an empty profession of faith/dead faith. So, James does not teach that we are saved "by" works. His concern is to show the reality of the faith professed by the individual (James 2:18) and demonstrate that the faith claimed (James 2:14) by the individual is genuine. Simple!
In James 2:19, we see that the demons believe "mental assent" that "there is one God," but they do not believe in the Lord Jesus Christ (Acts 16:31) and are not saved. Their trust and reliance is in Satan, as demonstrated by their rebellion in heaven and continuous evil works. There is a difference between mere "mental assent" belief (as the demons have) and saving belief in Christ, which the demons do not have.
In James 2:22, faith made perfect or complete by works means bring to maturity, to complete like love in 1 John 4:18. It doesn't mean that Abraham was finally saved based on merits of his works after he offered up Isaac on the altar in Genesis 22. When Abraham performed the good work in Genesis 22; he fulfilled the expectations created by the pronouncement of his faith in Genesis 15:6.
In James 2:24, James is not using the word "justified" here to mean "accounted as righteous" but is shown to be righteous. James is discussing the evidence of faith (says-claims to have faith but has no works/I will show you my faith by my works - James 2:14-18) and not the initial act of being accounted as righteous with God. (Romans 4:2-3) Works bear out the justification that already came by faith.
In the Strong's Exhaustive Concordance of the Bible, the Greek word for justified "dikaioo" #1344 is:
1. to render righteous or such he ought to be
2. to show, exhibit, evince, one to be righteous, such as he is and wishes himself to be considered
3. to declare, pronounce, one to be just, righteous, or such as he ought to be
In Matthew 12:37, we read - "For by your words you will be justified, and by your words you will be condemned." This is because our words (and our works) reveal the condition of our hearts. Words/works are evidences for, or against a man being in a state of righteousness.
God is said to have been justified by those who were baptized by John the Baptist (Luke 7:29). This act pronounced or declared God to be righteous. It did not make him righteous. The basis or ground for the pronouncement was the fact that God IS righteous. Notice that the NIV reads, "acknowledged that God's way was right.." The ESV reads, "they declared God just.." This is the sense in which God was "justified." He was shown to be righteous.
Matthew 11:19 "The Son of Man came eating and drinking, and they say, 'Behold, a gluttonous man and a drunkard, a friend of tax-gatherers and sinners!' Yet wisdom is justified/vindicated/shown to be right by her deeds."
Hebrews 11:1 - Now faith is the assurance of things hoped for, the conviction of things not seen.
So who obeys Him? The saved or the lost? I often hear works-salvationists cite this verse to try and support salvation by works, including Roman Catholics and Mormons.
Only genuine believers have obeyed Him by choosing to believe the gospel (Romans 1:16) in order to become saved, and only genuine believers obey Him after they have been saved through faith by practicing righteousness and not sin. (1 John 3:7-10) In either sense, only believers obey Him.
Unbelievers have not obeyed Him by refusing to believe the gospel (Romans 10:16) and without faith it's impossible to please God (Hebrews 11:6), so unbelievers do not obey Him no matter how much "so called" obedience that they attempt to conjure up through the flesh in a vain effort to receive salvation based on works. So, in either sense, unbelievers do not obey Him.