Newgen Previous Years Solved Sample Placement Papers
- Which of the following is true about servlets?
a) Servlets can use the full functionality of the Java class libraries b) Servlets execute within the address space of web server, platform independent and uses the functionality of java class libraries c) Servlets execute within the address space of web server d) Servlets are platform-independent because they are written in java
Answer: b) Servlets execute within the address space of web server, platform independent and uses the functionality of java class libraries Explanation: Servlets execute within the address space of a web server. Since they are written in Java, they are platform-independent, and the full functionality of Java class libraries is available. - When do exceptions in Java arise in the code sequence?
a) Run Time b) Compilation Time c) Can Occur Any Time d) None of the mentioned
Answer: a) Run Time Explanation: Exceptions in Java are run-time errors that occur when the program is executing. - Which of these keywords is not a part of exception handling?
a) try b) finally c) thrown d) catch
Answer: c) thrown Explanation: The five main keywords for exception handling are: try, catch, throws, throw, and finally. - Which of these keywords must be used to monitor for exceptions?
a) try b) finally c) throw d) catch
Answer: a) try Explanation: Thetry
block is used to monitor for exceptions in Java. - Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
a) try b) finally c) throw d) catch
Answer: d) catch Explanation: If an exception occurs in thetry
block, it is handled by thecatch
block. - Which of these keywords is used to manually throw an exception?
a) try b) finally c) throw d) catch
Answer: c) throw Explanation: Thethrow
keyword is used to manually throw an exception in Java. - What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { System.out.print("Hello" + " " + 1 / 0); } catch(ArithmeticException e) { System.out.print("World"); } } }
Answer: b) World Explanation: The1 / 0
causes anArithmeticException
, which is caught by thecatch
block, printing "World". Output:$ javac exception_handling.java $ java exception_handling World