If you look at the context, Paul wrote about justification before God, James wrote about justification before man ("if a man shall ask . . .").
The best example of salvation by faith is the thief on the cross who called out to Jesus to be remembered. Jesus told him he would be with Him in Paradise that same day. The thief had no opportunity to do any works.
But the thief did do a work. He believed.
How do u know the thief didn’t do the work before the cross?
It is evident he knew something of Jesus and His kingdom. He sure didn’t learn about Christ’s kingdom while hanging on the cross.
Just curious.....!
But he evidently had the faith that would in the ordinary (i.e., noncrucified) course of events have borne fruit in good works. It's not that works save - it's that the disposition to do good works is part of a true saving faith.