Potentially unsafe operations like pointer arithmetic, unchecked type casts, manual control over memory allocation and deallocation are disallowed.
Java does not run native machine code on the platform directly. Rather it runs an intermediate bytecode which is scrutinized by the JVM for unsafe operations
like writing to text segment of programs, accessing elements beyond array bounds etc.
Several standard cryptographic algorithms and secure communication protocols are inbuilt into the Java libraries allowing users to use them for enhanced security.
There is a security manager in Java which allows users to run untrusted bytecode in a "sandboxed" environment which restricts the usage of system resources by the program.
The security manager allows code with a valid digital signature to run with full privileges, thus enforcing security by accepting code from trusted sources only.
Note: Even with all of the above security mechanisms, Java has suffered in the past by virus and hacker attacks who were able to gain illegal access to system resources.
Yet, Java continues to be used widely because these issues have been addressed effectively and quickly (although Oracle has been sometimes criticised in being slow to provide fixes).
Got a thought to share or found a bug in the code? We'd love to hear from you: