Interest rate hikes can be problematic for many cash-strapped businesses. Taking on additional debt becomes more costly, with interest expenses chipping away at the bottom line. One way investors can protect themselves from this risky situation is by investing in businesses that are flush with cash and that can easily absorb rate hikes.

Two companies that will be just fine regardless of what happens with interest rates are Johnson & Johnson (JNJ -1.15%) and Microsoft (MSFT -2.45%). Here's why you can safely hide out in these stocks right now.

1. Johnson & Johnson

Johnson & Johnson is one of the top healthcare companies in the world. Last year, it generated $93.8 billion in sales. Its pharmaceutical business grew at a rate of 35%, and medical device sales also rose by more than 16%.

The company's healthy margins also mean that Johnson & Johnson banks a lot of that incremental revenue down in the bottom line. Over the past 12 months, its profit margin has been 21% of revenue; it reported net income of $19.8 billion on sales of $94.9 billion. Interest costs of just $130 million over that time don't even make a noticeable dent in the company's earnings.

Meanwhile, its free cash flow of $19.7 billion over the past 12 months, although strong, is simply par for the course -- in each of the past three years, Johnson & Johnson's free cash has been north of $19 billion. As of the end of March, the company had $30.4 billion in cash and short-term investments on its books, providing it with plenty of liquidity even if it does struggle, a scenario that looks unlikely.

Investors have been flocking to this stable stock as it is down only around 1% this year, which looks like an amazing return when compared to the S&P 500 and its year-to-date decline of more than 21%. The healthcare stock also pays a dividend that yields 2.7%, which is better than the S&P average of less than 1.4%. If you're worried about interest rates or just want a safe stock to hold on to right now, Johnson & Johnson could be a great option.

2. Microsoft

Microsoft doesn't look like a very safe stock this year; its shares have plummeted by nearly 28% in 2022. However, its strong fundamentals are a key reason it's likely to recover from this recent sell-off. The business is still growing and is doing so while reporting excellent profits and cash flow.

In its third-quarter report, which covered the first three months of the year, revenue rose by 18% year over year to $49.4 billion. Microsoft was one of the few tech stocks last quarter that did well and beat expectations on both the top and bottom lines. Its cloud platform, Azure, continued to generate impressive growth, with sales rising by 46% year over year. Many of its segments achieved double-digit growth, including LinkedIn, which was a top-performing area of Microsoft's business, growing at a rate of 34%.

The company's cash and short-term investments as of the end of Q3 stood at an incredible $104.7 billion. Interest expenses totaling $2.1 billion over the trailing 12 months accounted for less than 3% of the company's operating income. And over the past four quarters, Microsoft's free cash has totaled $63.6 billion.

Microsoft's business remains strong and is in even better shape than Johnson & Johnson's. Although the stock is down and the company did recently trim its guidance due to foreign exchange, its future remains bright. For multiple decades, this has been a top tech business to invest in, and nothing today suggests that the future will be any different.