Notes
In Apex, a public class can be accessed by any Apex code within the same namespace, while a global class can be accessed by code outside the namespace as well. Here's a brief summary of the differences between the two:
Access: A public class can be accessed by any Apex code within the same namespace, while a global class can be accessed by code outside the namespace as well.
Visibility: A public class is only visible to code within the same namespace, while a global class is visible to code outside the namespace as well.
Namespace: A public class is restricted to the namespace in which it is defined, while a global class can be accessed from any namespace.
Integration: Global classes are typically used for integration purposes, such as exposing an API to external systems.
Security: Global classes may introduce security concerns, since they can be accessed from outside the namespace.
In general, you should use a public class unless you specifically need to make the class globally accessible. Global classes should be used sparingly, as they can introduce security risks and make it more difficult to manage dependencies between different parts of your code.