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 says it would release an update malware removal tool to remove infections.
In January, the U.S. Department of Homeland Security recommended disabling Java in Web browsers to avoid hacking attacks.