How does Java enforce security restrictions on code loaded over the network?

Java secures code loaded from external or untrusted sources by applying a permission-based security model. The JVM verifies the code, checks its origin, and restricts its access to sensitive system resources. This prevents potentially harmful code from performing unauthorized operations on the host machine.

Key Points: • The JVM performs bytecode verification to ensure the loaded code follows Java's safety rules and cannot corrupt memory. • Security policies and permissions control access to resources such as files, network connections, system properties, and runtime operations. • Class Loaders help isolate code from different sources and play a key role in maintaining a secure execution environment.

Example: Consider a Java application downloading a plugin from a remote server. The JVM can restrict that plugin from deleting files, accessing confidential data, or opening unauthorized network connections unless explicit permissions are granted.

Interview Tip: A concise interview answer is: Java enforces security on network-loaded code through bytecode verification, Class Loaders, and a permission-based security model. These mechanisms ensure that untrusted code runs in a controlled environment with restricted access to system resources, protecting the application and operating system from malicious actions.