Japan was taking a preemptive strike. They knew the U.S would attack them when they invade their territories. They wanted to take out the U.S Navy to prevent them from fighting back for a while. That didnt work.