If you do ride on the sidewalk, it's good to assume that:
1)sometimes people will step out of buildings or around corners without looking, because it's supposed to be pretty safe to do so on a sidewalk. A bicycle has to go slowly enough to avoid this problem.
2)most motorists will cross driveways and intersections without thinking about whether there is a sidewalk bicyclist who might get hit. The only way to avoid this is to go slowly enough that your stopping distance is nearly zero (like a pedestrian) whenever there could be a car crossing your path unexpectedly. (which means pretty much any driveway connected to a street with cars nearby on it, and intersection with cars nearby).