Q:

"I realized I had forgotten something" vs "I realized having forgotten something"

Are the following expressions both correct?  

I realized I had forgotten something.
I realized having forgotten something.

What is the difference in the meaning (if any)?  

A:

I realized [that] I had forgotten something.

This is grammatically correct, and probably what you wanted to say. realized is in simple past, so you are talking about something that happened in the past. had forgotten is past perfect, which places it before the realizing. 
Note that realize is usually followed by a that-clause, although the that is often omitted.

I realized having forgotten something.

On its own, this sentence is incomplete. having is a participle, and Having forgotten something is a participial phrase. Remember that realize requires a that-clause, and a phrase won't do. (A clause contains a verb, a phrase does not).
You might use it in a sentence like this, where there is an additional that-clause:

Having forgotten something, I realized that I would have to go back and get it.

A:

To realize is a reporting verb that can be followed either by "that- clause" or a clause starting with a question word (what, how, etc.). In "that-clause", that is often omitted, like it was in your first sentence.
Examples:

Only then did I realize that he was telling the truth. 
Looking in his eyes, I realized how serious he was. 
Having read the letter, I realized what she really meant by saying that.

As for your second sentence, I can't but absolutely agree with JavaLatte.
P.S. The provided links will lead you to the lists of numerous reporting verbs  and their usage to help you further your English.

