The stock market has been fairly volatile over the past three years, which isn't surprising given the worldwide crises we have experienced. Further, the economy continues to face challenges, such as high inflation and the possibility of a coming recession. It might be tempting to give up on investing in stocks in this environment.

But an alternative strategy is to purchase shares of safe companies that generate steady revenue and profits and offer solid dividends. Such stocks can help investors navigate almost any market downturn. Let's look at two that fit the bill: Johnson & Johnson (JNJ -0.69%) and AbbVie (ABBV -1.03%).

1. Johnson & Johnson

Johnson & Johnson is one of the largest healthcare companies in the world, and typically generates higher sales than most other pharmaceutical peers. The drugmaker boasts a rich roster of medicines in various areas, such as immunology, oncology, infectious diseases, neuroscience, and more. And J&J routinely expands its lineup thanks to a deep pipeline. 

In the first nine months of the year, the company reported $71.2 billion in sales, representing a 2.3% increase year over year. The company's adjusted earnings per share (EPS) came in at $7.81, 1.8% higher than the prior-year period.

Johnson & Johnson will soon spin off its consumer health division, which made up a non-negligible 15.7% of its total sales during the first three quarters of the year. But this unit has been slower growing than J&J's other business segments and has also been facing dozens of lawsuits associated with some of its products. What will remain are J&J's core pharmaceutical and medical devices operations, which generate higher profits. 

Meanwhile, the company continues to pay attention to its shareholders. J&J boasts strong free cash flow, and it recently announced a $5 billion share repurchase program. J&J is also a member of the elite club of Dividend Kings. The drugmaker has raised its payouts for 60 consecutive years. It currently offers an above-average yield of 2.58%.

Investors can be highly confident that Johnson & Johnson will continue raising its dividends for a long time. After all, the company isn't going anywhere. Lifesaving drugs and innovative medical devices will only become more important as the world's population ages. That'll provide a major tailwind for Johnson & Johnson. As a leader in both fields, it is more than capable of profiting from these long-term trends.

The company has survived many recessions over its more-than-100-year history. That's more evidence that it can be a safe haven in today's challenging environment. 

2. AbbVie

AbbVie is also a leading pharmaceutical company best known for its immunology drugs, particularly rheumatoid arthritis medicine Humira. But the company's lineup goes well beyond this product -- it also boasts other exciting medicines, including immunosuppressants Rinvoq and Skyrizi, its Botox franchise, cancer medicines Venclexta and Imbruvica, and more. 

The worry for AbbVie is that Humira will lose patent protection next year. This medicine brought in $20.7 billion in sales last year. Having to face generic competition could harm AbbVie. Thankfully, the company is confident that Skyrizi and Rinvoq can take over. Management even predicts that these two medicines combined will exceed Humira's peak revenue.

Meanwhile, AbbVie continues to generate solid top and bottom lines. In the nine months ended Sept. 30, the company's revenue grew by 3.9% year over year to $42.9 billion. AbbVie's adjusted EPS came in at $10.18, 16.3% higher than the comparable period of the previous fiscal year. AbbVie keeps on earning new approvals, including several during the third quarter, thanks to money it pours into research and development and a rich pipeline.

The company's robust business can support its generous dividend. AbbVie is also a Dividend King, and it offers a yield of 3.82%. And in the past five years alone, a period that includes the devastation caused by the COVID-19 pandemic, AbbVie has raised its payouts by 108%. AbbVie won't stop rewarding its shareholders anytime soon, no matter what the economy throws at the markets next.