where should private and public keys be stored? I am kind of confused whether should a newly generated key pair be stored in a keystore or in just a normal plain text file?

From what I read from online source, there are serveral explainations about what the keystore actually store.

some says it stores the certificates only while some says it stores the key pair as well as the digital certificates.

and if the answer is storing in a normal plain text file, won't that be insecure?
You should keep the private key as safe as possible. How safe depends on the security requirements and risk assessment. A key store, such as a PKCS#12 key store or Java key store enables you to store a key protected by - usually - a password. This is obviously more secure than storing it as plaintext at the same location.

It is possible to mitigate the risk of storing in plain by using e.g. a thumb drive as storage device, and only use the storage instead.

Another form of key store may be present on a device such as a TPM, a HSM or smart card. Such devices usually protect against dictionary and brute force attacks by minimizing the attack surface - e.g. by blocking after a maximum incorrect log in attempts.

A key store may contain a certificate chains for private keys of the user, but it may also store trusted certificates. Trusted (root) certificates are for instance used to create TLS connections from your browser to websites. TLS can also be configured to use client authentication; in that case the key store contains both the private key + certificate chain and trusted certificates.

If a key store just contains certificates then it is usually called a trust store instead.

Use a key store if you can, especially those provided by the runtime system. A runtime system can often make use of lower level security mechanisms and provide a higher level of trust than mere applications can.



Note that some API's such as Microsoft .NET  act as if private keys are part of a certificate. They are not; although the public and private keys are part of one key pair, the private key and certificate are distinct. In Java the (E)JKS key stored contain a private key and certificate chain per key entry but they are retrieved separately.

These key stores are not really generic, they have been build for X509 compatible PKI (as used in browsers).