Dogs are excellent alarm systems. Provided you train them not to bark when it's not necessary.

Of course, alarm systems are excellent alarm systems too.

Reinforcing doors and windows is good.

Putting up a fence, even a low one, is good.

Planting prickly plants under windows is good.

Motion sensor lights outside are good.

Keeping a charged cell phone in the bedroom with you at night is good.

Doing all of the above may prevent a problem before the need for a gun comes into play. If that need does arise, the presence of all of the above measures can only reflect on you in a positive way, and may provide partial evidence of intent of the bad guy.