Correct Answer: Correct answer is: (C) @MatrixParam.
Exam Relevance: Java EE, JAX-RS, RESTful Web Services
Difficulty: Moderate
Concept notes: In JAX-RS, the @MatrixParam annotation is used to bind a parameter passed to a method to a HTTP matrix parameter in the path.
Common Mistakes: Students often confuse @MatrixParam with @PathParam or @QueryParam, which are used for different purposes.
Explanations: The @MatrixParam annotation is specifically designed to bind parameters that are part of the matrix parameters in the URI path. Matrix parameters are name-value pairs that appear after a semicolon in a path segment. For example, in the path "/users;age=25", "age" is a matrix parameter. The @MatrixParam annotation allows you to extract and use these matrix parameters within your JAX-RS methods.
Option Analysis: - Option A: @PathParam is used to bind a parameter to a path segment, not to matrix parameters.
- Option B: @QueryParam is used to bind a parameter to a query parameter in the URL, not to matrix parameters.
- Option C: @MatrixParam is the correct annotation for binding parameters to matrix parameters in the path.
- Option D: @HeaderParam is used to bind a parameter to an HTTP header, not to matrix parameters.
Mnemonic: Matrix for MatrixParam, Path for PathParam, Query for QueryParam, Header for HeaderParam.