The company said no data had been taken and it was investigating the incident with the authorities.
Facebook was targeted by a hacking attack just last week, while Twitter has also been a victim.
Apple said in a statement: “Apple has identified malware which infected a limited number of Mac systems through a vulnerability in the Java plug-in for browsers. The malware was employed in an attack against Apple and other companies, and was spread through a website for software developers. We identified a small number of systems within Apple that were infected and isolated them from our network.
“There is no evidence that any data left Apple.”