Johnson & Johnson's pharmaceutical business fueled the company's second-quarter growth, while its consumer unit lagged.

The sprawling health company beat revenue and earnings estimates for the quarter and narrowed its full-year forecast. J&J's pharmaceutical business and medical device segments topped expectations, while its consumer unit fell short.

Here's how the company did compared with what Wall Street analysts polled by Thomson Reuters expected:

Adjusted earnings: $2.10 vs. $2.07 per share

Revenue: $20.8 billion vs. $20.39 billion

“It feels like consumer and (medical devices) are still in turnaround mode a bit,” said Jefferies analyst Jared Holz. “The analyst day they recently had, the key component was to get the focus on the longer-term growth dynamics of those businesses versus the near term. I think that’s sort of what you’re seeing here.”

J&J reported net income of $4 billion, or $1.45 per share, in the second quarter. After stripping out amortization expenses and special items, the company earned $5.7 billion, or $2.10 per share, topping analyst estimates of $2.07 per share from Thomson Reuters.

Revenue hit $20.8 billion, up 10.6 percent from the previous year, surpassing estimates of $20.39 billion.

On an operational basis, J&J's revenue grew 8.7 percent. Excluding the impact of acquisitions, divestitures and currency, worldwide sales were up 6.3 percent.

J&J refined its full-year revenue forecast to between $80.5 billion and $81.3 billion, from a previously given $81 billion and $81.8 billion. This reflects growth between 4.5 and 5.5 percent when excluding currency. It tweaked its full-year adjusted earnings forecast to between $8.07 and $8.17 per share from $8 and $8.20 per share, representing operational growth between 8.5 percent and 9.9 percent.

"When you look at the forecast, our operational performance continues to do extremely well," Chief Financial Officer Joe Wolk told CNBC's "Squawk Box." "So we actually took that portion of our guidance up, and what you see on a reported basis is the impact of negative currency, or better said, less favorable currency than what we had been seeing as the dollar has strengthened here."

Pharmaceuticals, particularly cancer drugs, have fueled J&J’s success. In the quarter, the business posted $10.4 billion in revenue, a 20 percent year-over-year increase that topped expectations of $9.95 billion, according to consensus estimates from StreetAccount. Excluding the net impact of acquisitions and divestitures, worldwide sales rose 17.6 percent.

Worldwide sales of oncology drugs reached $2.46 billion, an increase of 42.2 percent, or 38.7 percent when excluding currency, from the year-ago quarter.

Darzalex, a multiple myeloma treatment, worldwide revenue soared nearly 80 percent to $511 million, up from $299 million in the year-ago quarter and above analysts' expectations of $465.7 million. When excluding currency, revenue increased 68 percent.

J&J's medical device unit increased 3.7 percent on an operational basis from last year, reaching $7 billion and topping Street estimates of $6.90 billion. Excluding the net impact of acquisitions and divestitures, worldwide sales increased 1.9 percent.

The company has continued pruning its medical device business, including selling its LifeScan diabetes unit to private-equity firm Platinum Equity for $2.1 billion. It received a binding offer last month from Fortive Corp. for its Advanced Sterilization Products business for $2.8 billion.

Vision continued to be a bright spot within the segment. Sales reached $1.17 billion, up 11.2 percent from the $1.05 billion posted in the year-ago quarter. On an operational basis, sales increased 9.6 percent.

Consumer, meanwhile, continued to lag. In the quarter, it generated $3.50 billion in revenue, up 0.7 percent from the year-ago quarter and short of the $3.59 billion analysts had expected. On an operational basis, worldwide sales fell 0.4 percent. J&J's Wolk said they were "a little bit disappointed."

J&J's namesake baby care line has been a weakness for the company. Worldwide revenue declined 7.7 percent, or 6.9 percent when excluding currency. The heaviest losses came from the U.S., where sales tumbled about 21 percent.

J&J plans to roll out its revamped baby care line in August. On a call with analysts Tuesday, Wolk said retailers resetting their shelves with the new products hurt the group's performance in the quarter.

A Missouri jury last week ordered J&J to pay $4.69 billion to 22 women who claim the company's talc-based products, including its baby powder, contained asbestos and allegedly caused them to develop ovarian cancer. J&J has vowed to fight the verdict.

"As you know our baby powder is a trusted product that we sold to families for over 100 years and Johnson & Johnson is deeply disappointed in this verdict," CEO Alex Gorsky said on a call with analysts. "Now, we remain confident that our products do not contain asbestos and do not cause the varying cancer and we intend to pursue all available appellate remedies."

Shares of J&J gained 3.5 percent Tuesday after initially sliding more than 2 percent in premarket trading.