0 9

BIT401 ยท 0 ยท 5 marks

Write short notes on a. Container Classes b. Scope of JSP Objects

Write short notes on a. Container Classes b. Scope of JSP Objects [5]

Advanced Java ProgrammingChapter 10: Java Collections and Advanced FeaturesContainer classes and collections

Quick answer

Container classes are classes that hold or manage collections of other objects. They provide a mechanism to store, organize, and manipulate groups of objects as a single unit.

Model Answer: Container Classes and Scope of JSP Objects

a. Container Classes

Key characteristics:

  • Store multiple objects of the same or different types
  • Provide methods to add, remove, retrieve, and iterate through elements
  • Examples: Vector, ArrayList, HashMap, HashSet, LinkedList
  • Implement the Collection interface (in Java)
  • Allow dynamic resizing of data structures
  • Provide convenient access to stored elements through various methods

Common operations:

  • add() - insert elements
  • remove() - delete elements
  • get() - retrieve elements
  • size() - get number of elements
  • iterator() - traverse elements

Container classes are fundamental to managing data collections efficiently in object-oriented programming.


b. Scope of JSP Objects

JSP objects have different scopes that determine their lifetime and accessibility within the application:

1. Page Scope

  • Object exists only within a single JSP page
  • Destroyed when page processing completes
  • Not accessible to other pages
  • Default scope for most JSP objects

2. Request Scope

  • Object exists for the duration of a single client request
  • Accessible to all pages involved in handling that request (including forwarded pages)
  • Destroyed after response is sent to client

3. Session Scope

  • Object persists across multiple requests from the same user
  • Maintained for the entire user session
  • Destroyed when session expires or user logs out
  • Useful for storing user-specific data

4. Application Scope

  • Object exists for the entire application lifetime
  • Shared across all users and sessions
  • Destroyed only when application stops
  • Used for global application data

Scope declaration syntax: <jsp:useBean id="name" class="ClassName" scope="page|request|session|application" />

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.