Java Servlets, JSP and C Programming Quiz
Test your knowledge of Java Servlets, JSP, and C programming concepts including syntax, methods, and common programming pitfalls.
Questions
Given the following jsp line select the correct statements: <% public void jspInit() { ...java code...} %>
- 1) It is a valid line that can be used to initialize the servlet that implements the jsp file.
- 2) It won't compile as no identifer can start with jsp not _jsp.
- 3) It will serve as the servlet initialization if the function's name is _jspInit.
- 4) There is no way to initialize a jsp's implementation class servlet.
What will be printed out if this jsp code? <%! java.util.Locale class1=request.getLocale(); %> <%= class %>
- 1) It won't compile.
- 2) It will print the default client's Web browser locale.
- 3) It will print the default web server Locale.
- 4) It will the first language specified in the Accept-Language request's header.
What is the return type of the getLastModified method of HttpServlet?
- 1) java.util.Date
- 2) java.sql.Date.
- 3) int.
- 4) long
What will be the result of running the following jsp file taking into account that the Web server has just been started and this is the first page loaded by the server? <%= request.getSession(false).getId() %>
- 1)It won't compile
- 2)It will print the session id.
- 3)It will produce a NullPointerException as the getSession(false) method's call returns null, cause no session had been created.
- 4)It will produce an empty page.
What statements are correct about the method PageContext.findAttribute(String name)?
- 1) There is no such method.
- 2) It searches the attribute in all 4 scopes.
- 3) It searches the attribute in page scope.
- 4) The method is findAttribute(String name, int scope)
. Which are mandatory elements of the web-resouce-collection element?
- 1) web-resource-name
- 2) url-pattern
- 3) http-method
- 4) auth-constraint
What are the types returned by the ServletContext method getResource and getResourceAsStream?
- 1) ServletContext doesn't have one of these two methods.
- 2) String and InputStream
- 3) URL and InputStream
- 4) URL and StreamReader
Which of the following statements regarding HttpRequest methods are correct?
- 1) getHeaderNames returns an Enumeration
- 2) getHeaders returns a String[]
- 3) getHeaderValues returns a String[]
- 4) getIntParameter returns an int
Which statements are correct about the method PageContext.include?
- 1) There is no such method.
- 2) It has two paramters: request and response
- 3) It has one parameter of type String which is the relative URL of the page to include.
- 4) This method is appropiate to use within a Tag class.
Which of the following statements PageConext methods pushBody and popBody are true?
- 1) pushBody is called by the jsp container after doStartTag and before doAfterBdy
- 2) pushBody is called by the jsp container before doInitBody
- 3) popBody is called by the jsp container after doAfterBody and before doEndTag
- 4) popBody is called by the jsp container after doEndTag
. Is it true that all tags have a parent tag,which is null for top-level tags, and is the innermost containing tag for nested tags.
- 1) yes
- 2) no
- 3) only the second part of the statement is true.
- 3) only the first part of the statement is true.
You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make sure that the user continues in the same session. How do you that?
- 1) By calling the method with an absolute path as the argument
- 2) By enconding the path with HttpServletResponse.endcodeURL method
- 3) By enconding the path with HttpServletResponse.endcodeRedirectURL method
- 4) If you use sendRedirect the session is lost.
Which statements are true about the auth-constraint element?
- 1) It only contains the element role-name (besides element description)
- 2) Only the role-name specified in security-role-ref can be used
- 3) It is a subelement of web-resource-collection
- 4) It is related to authentication
class a { public staic void main(String ar[]) { String s="abcxyz"; s.substring(2,5) System.out.println(s); } }
- cxy
- abcxyz
- cxyz
- bcxy
A class without main method can be compiled successfuly.
- True
- False
class a { public staic void main(String ar[]) { String s="abcxyz"; s.substring(2,5); System.out.println(s); } }
- cxy
- abcxyz
- bcxy
- cxyz
Find the output of this program.1. void main(){ float j; j=1000*1000; printf("%f",j); }
- 1000000
- Overflow
- None
- Error
Find the output of this program. 1. void main(){ float j; j=1000*1000; printf("%f",j); }
- 1000000
- Overflow
- None
- Error
Find the output of this program. main() { int a[10]; printf("%d",*a+1-*a+3) ; }
- Compiler error
- 3
- -2
- 4
Find the output of this program. main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }
- -1
- 1
- 0
- Compiler error