There seems to be an underlying assumption in questions like these, specifically that if God is really loving, then He is obligated to prevent any harm from ever coming to anyone. In fact, He should create a world where everything is perfect--which is actually what He did, but even in that world mankind rejected God.
It is also instructive to note that bad things can often have good results. In fact, as Romans 8:28, God works out even bad things for our good. When we experience death and loss in this life, is it not a potent reminder that we were not made for this world, but for another? When we see evil, is it not a great teacher that all people desperately need the power of God to transform our hearts? Do not all the trials and frustrations of this life teach us that there is more to life than physical life?
This is the problem with the question--we view things from a worldly perspective, wanting to see all the blessings of God confined to a few years on this planet, and if we don't, then God must not be loving. The Bible teaches about an eternity where all the infinite riches of God's blessing can be experienced. Job will no doubt, as does a woman giving birth, forget the pain for the joy to come.
The story is told of a missionary who spent his life in a distant country bringing the gospel of God to a remote tribe. In his later years, he returned home on a boat, which, once it came into port, was greeted with much fanfare--none of which was for him. There was no one to welcome him home or thank him for his sacrifice, even though many had come to welcome home others who were aboard.
The man prayed and asked God, "I have given my life and strength for your kingdom. Why is there no one to welcome me home." Then the man felt the Lord saying to him, "You're not home yet."
Conclusion
So, was God playing a cruel joke on Job? No. Did He allow evil to happen? Yes. In fact, all evil that ever happens could certainly be prevented by God. And if God's ultimate goal was the physical well-being of all mankind, then He would certainly do so.
God's ultimate goal is much greater than that--it is the spiritual well-being of all mankind. God desires for all mankind everywhere to see the vanity of all this world has to offer and to turn to Him that He may bless us richly, not merely in physical ways and not merely in this life.