Fundamentals of lateral and vertical heterojunctions of atomically thin materials