Safety is a relative thing. Because Java runs in a virtual machine, it can protect it on its own for some of the classic problems observed in C.
routine stack overrun - common worm and virus attack
Java has a specific behavior when throwing a StackOverflowError, and you cannot get around this.
memory corruption outside the process's own space
IMHO, this is really an OS consideration. Your OS can protect your processes from changing the memory of other processes, even in C. Java protects you from the fact that I do not allow you to access local repositories, regardless of whether the OS provides this object or not. Most modern operating systems provide this protection.
reading or writing files without permission.
Again, your OS can protect you from this in C and should be your first line of defense. What Java does is you can run code that is not trusted and does not protect your files, even if you can access them, but do not let one of your programs access them. Java has two mechanisms: SecurityManager and AccessControl.
source share