How do we use the Java public api to define our own type?Especially user and group.
The two parts of the question don't make much sense together. First of all, you do not define your own types via the public API - you define them by bootstrapping a content model XML file at startup. See content model tutorials.
Do you want to create a custom type for representing users / groups? Otherwise I don't understand the second part at all. Typically you do not need to create types for users / groups since Alfresco already provides its own and only suports these. You can of course define aspects which you can use to enhance the user / group nodes that Alfresco creates with additional metadata.