Apple said it is working with law enforcement to find the source of the malicious software.
Apple said hackers have attacked the computers of some its employees in California, but there was no evidence of data stolen.
The attack on Apple is similar to the one recently carried out against Facebook, which said hackers exploited an unnoticed security flaw in Oracle's Java software last month.
Apple said it has identified the 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," Apple said.
"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."
The iPhone maker said it is working with law enforcement agencies to find the source of the malicious software.
Earlier this month, Twitter had been the victim of cyber-attacks after 250,000 users' passwords, names, emails and other data were compromised.