Apple says a small number of Mac computers at its offices were infected by malicious software, in an attack similar to the one Facebook acknowledged last week.
In both cases, computers were infected through software downloaded from a site for software developers. The attacks took advantage of flaws in the Java plug-in for web browsers.
Neither company said that there was any evidence that the attackers gleaned any data from their attacks.
The Java vulnerability is well known, and Apple has taken measures to disable the plug-in on all Macs. It has since released a security update for Mac users.
In January, the U.S. Department of Homeland Security recommended disabling Java in web browsers to avoid hacking attacks.