Yosemite is a LONG way away for a 2.5 day weekend. You will have time to drive through the park, but you will miss so much! That said, it is still worth it, if for no other reason than to entice you to make a longer trip of it next time, and you will have all of Sunday in the park. My brother once left LA in the morning, hiked half dome that day with a friend, and late that night drove up to Washington to get to a wedding! So yes, it can be done, but prepare to be exhausted; You will be able to drive during the day (leaving the park very early Monday) so you will be much safer on Hwy 395 during the day, and the first part of it really is spectacular scenery. I say go for it, just plan on pushing yourself hard and relying on your adrenaline.
One option for Joshua Tree is to begin a hike before dawn. If the moon is out, you won't need a flashlight. Walking through Joshua trees under a full moon is up there with some of my most surreal things I've done, and is a truly unique experience. Ascending granite boulders at sunrise will be a beautiful experience. You could get in a pretty good hike before it gets too hot, and then head back to town in the afternoon heat. Better yet, head to the Desert Hot Springs to stay cool.