Java is known for being platform independent. What feature of Java makes this possible?
Think about how Java code runs on different computers without changing the code.
Java compiles code into bytecode, which is a universal code run by the JVM. The JVM is available on many platforms, so the same bytecode runs anywhere.
Java is considered a secure programming language. Which feature mainly contributes to this?
Think about how Java controls what a program can do on your computer.
The Java security manager restricts programs from accessing unauthorized resources, making Java programs safer to run.
What is the output of the following Java code?
class Animal { void sound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } } public class Test { public static void main(String[] args) { Animal a = new Dog(); a.sound(); } }
Think about which method runs when a parent reference points to a child object.
Java uses dynamic method dispatch. The method of the actual object (Dog) runs, so it prints "Dog barks".
What will be printed when the following Java code runs?
public class Test { public static void main(String[] args) { try { int a = 5 / 0; System.out.println("No Exception"); } catch (ArithmeticException e) { System.out.println("Arithmetic Exception caught"); } finally { System.out.println("Finally block executed"); } } }
Think about what happens when dividing by zero and how try-catch-finally works.
Division by zero throws ArithmeticException, caught by catch block which prints the message. The finally block always runs.
Which reason best explains why Java is widely used in large business applications?
Think about what big companies need from a programming language for their applications.
Java's automatic memory management, ability to handle many users at once (multithreading), and extensive libraries make it ideal for big business software.