Java Question Bank a Section Answers
Java Question Bank a Section Answers
1. Characteristics of identifiers: Must begin with a letter, $, or _; cannot start with a digit; are case-sensitive;
2. Purpose of comments: Improve code readability and maintainability; help in documentation; ignored by the
compiler.
3. Types of inheritance: Single, Multilevel, Hierarchical, Multiple (via interfaces), and Hybrid inheritance.
4. Operators in Java: Arithmetic, Relational, Logical, Bitwise, Assignment, Unary, Ternary, and instanceof
operator.
5. Downcasting with an instance: Refers to casting a superclass reference to a subclass type. Example:
6. Purpose of `:`: Used in enhanced for-loops (for-each) and in ternary conditional operators.
7. Reason behind `public class Main {`: `public` allows access from outside the package; `class Main` defines
the class named Main; Java starts execution from public static void main.
8. Static class methodology: In Java, static nested classes are associated with the outer class and can
9. Packages vs Interfaces similarities: Both promote modularity, help in code reusability, improve
10. Using static methods: Static methods belong to the class, not instances. Example: class MathUtil { static
11. Types of packages: Built-in (java.lang, java.util, java.io) and user-defined packages.
12. `super` and `final`: `super` refers to the parent class; `final` prevents method overriding, inheritance, and
reassignment of variables.
13. Exception handling reason: Handles runtime errors, maintains normal program flow, and improves fault
tolerance.
14. Multithreading with example: class MyThread extends Thread { public void run() {
System.out.println("Thread running"); } }
16. Reasons for Exception handling: Avoid abnormal termination; provide alternate solutions; error tracking.
18. States in Multithreading: New, Runnable, Blocked, Waiting, Timed Waiting, Terminated.
19. Print Output methodology: Use of System.out.print(), System.out.println(), and System.out.printf() for
output display.
20. Pass parameters to applet: Using <param> tags in HTML and getParameter(String name) in applet code.
21. Properties of Java Servlet: Platform-independent, secure, efficient, scalable, server-side components.
24. Class and constructor relation: Constructor is a special method invoked during object creation to initialize
members.
25. Method overriding: Redefining a superclass method in a subclass with the same signature.
26. Using static methods: Same as Q10; helps utility methods, shared logic without needing instances.
29. Using layout managers & menus: FlowLayout, BorderLayout, GridLayout. Menus: MenuBar, Menu,
MenuItem.
30. Working with graphics and fonts: public void paint(Graphics g) { g.setFont(new Font("Arial", Font.BOLD,
32. Windows Fundamentals purpose: Develop GUI apps; provide platform for graphical components like
frames, buttons.
33. Event handling & Adapter classes: Adapter classes provide empty implementations of listener interfaces;
36. Servlet container reason: Manages servlet lifecycle, communication between client and server, and
resources.
37. Key features of servlets: Persistent, efficient, scalable, support for sessions, platform-independent.
38. Servlet Container role: Also known as servlet engine (e.g., Apache Tomcat); executes servlets and
39. Application Architecture example: MVC (Model-View-Controller). Example: JSP (View), Servlet
while(rs.next()) { System.out.println(rs.getString("username")); }