Java Servlets and Core Programming
Quiz covering Java Servlets, web deployment, method overriding, and loop constructs
Questions
package loop; public class TestLoop2 { public static void main(String[] args) { int p = 100; do { while(p>100) { System.out.println("I am in while"); } System.out.println("I am in do-while"); } while (p > 100); } }
- I am in do-while
- I am in while I am in do-while
- Compiler Error
- No output
package loop; public class TestLoop3 { public static void main(String[] args) { int p = 0; for (int i = 0; i < 3; i++) { p = i+1; if (p == 2) { continue; } System.out.println("i in loop = " + i); } } }
- i in loop = 0 i in loop = 1 i in loop = 2
- i in loop = 0 i in loop = 0 i in loop = 1 i in loop = 2
- i in loop = 0 i in loop = 2
- Compiler Error
package loop; public class TestLoop4 { public static void main(String[] args) { for(int i=1,j=1; i<2,j<2;i++,j++) { System.out.println("i= "+i+" j = "+j); } } }
- Compiler Error
- i= 1 j = 1
- i= 1 j = 0
- Exception
package loop; public class TestLoop6 { void testFor() { for (int i = 1; i < 10; i++) { System.out.println("i in for loop = " + i); if (i == 1) { return; } } System.out.println("For loop over"); } public static void main(String[] args) { TestLoop6 tl = new TestLoop6(); tl.testFor(); System.out.println("Method call over"); } }
- i in for loop = 1 For loop over Method call over
- i in for loop = 1 Method call over
- Compiler Error
- Exception
package loop; public class TestLoop1 { void testFor() { for (int i = 1; i < 3; i++) { System.out.println("i in for loop = " + i); if (i == 1) { break; } } System.out.println("For loop over"); } public static void main(String[] args) { TestLoop1 tl = new TestLoop1(); tl.testFor(); System.out.println("Method call Over"); } }
- i in for loop = 1 i in for loop = 2 For loop over Method call Over
- i in for loop = 1 For loop over Method call Over
- Compiler Error
- i in for loop = 1 Method call Over
package overriding; class Super1 { void testSuper(int empId) { System.out.println("I am in Super " + empId); } } public class TestOverrideSub1 extends Super1 { private void testSuper(int empId) { System.out.println("I am in Sub " + empId); } public static void main(String[] args) { Super1 s1 = new TestOverrideSub1(); s1.testSuper(144670); } }
- I am in Sub 144670
- Compiler Error
- I am in Super 144670
- Exception
package overriding; class Super3 { void testDivide(int i, int j) throws Exception { double p = i / j; System.out.println("p in Super =" + p); } } public class TestOverrideSub3 extends Super3 { void testDivide(int i, int j) throws ArithmeticException { double p = i / j; System.out.println("p in Sub =" + p); } public static void main(String[] args) { Super3 s3 = new TestOverrideSub3(); try { s3.testDivide(10, 5); } catch (Exception e) { System.out.println("Exception " + e.getMessage()); } } }
- p in Super =2.0
- p in Sub =2.0
- Compiler error
- Exception
package overriding; class Super2 { void testSuper(int empId) { System.out.println("I am in Super " + empId); } } public class TestOverrideSub2 extends Super2 { public void testSuper(int empId) { System.out.println("I am in Sub " + empId); } public static void main(String[] args) { Super2 s2 = new TestOverrideSub2(); s2.testSuper(144670); } }
- I am in Sub 144670
- I am in Super 144670
- Compiler error
- Exception
package overriding; class Super4 { final void testSuper() { System.out.println("I am Super"); } } public class TestOverrideSub4 extends Super4{ void testSuper() { System.out.println("I am Sub"); } public static void main(String[] args) { Super4 s4 = new TestOverrideSub4(); s4.testSuper(); } }
- Compiler Error
- I am Sub
- I am Super
- Exception
package overriding; class Super5 { int testAdd(int x,int y) { System.out.println("Super Add "+(x+y)); return(x+y); } } public class TestOverrideSub5 extends Super5{ long testAdd(int x,int y) { System.out.println("Sub Add "+(x+y)); return(x+y); } public static void main(String[] args) { Super5 s5 = new TestOverrideSub5(); s5.testAdd(5,5); } }
- Compiler Error
- Exception
- Sub Add 10
- Super Add 10
The __________ attribute is used to declare variables based on definitions of columns in table.
- %ROWTYPE
- %TYPE
- AS_COLUMN
- None of the above
Which of the HTTP methods below is not considered to be "idempotent"? (Choose one.)
- GET
- TRACE
- POST
- HEAD
- OPTIONS
- SERVICE
Which of the HTTP methods below are likely to change state on the web server? (Choose three.)
- DELETE
- TRACE
- OPTIONS
- POST
- PUT
- HEAD
What is the maximum number of parameter values that can be forwarded to the servlet from the following HTML form? (Choose one.)
Chapter 1 Question 9
- 2
- 3
- 4
- 5
- 6
- 7
Which of the following directories are legal locations for the deployment descriptor file? Note that all paths are shown as from the root of the machine or drive. (Choose two.)
- /WEB-INF
- /appserverInstallDirectory/webapps/webappName/WEB-INF/xml
- /appserverInstallDirectory/webapps/webappName/WEB-INF
- /appserverInstallDirectory/webapps/webappName/WEB-INF/classes
Which of the following servlet methods can return null? (Choose one.)
- getInitParameterNames()
- getInitParameter(String name)
- getServletName()
- getServletContext()
Identify correct statements about the META-INF directory from the list below. (Choose three.)
- META-INF is a suitable location for storing digital certificates.
- META-INF is used as a repository for common code.
- The MANIFEST.MF file is found in the META-INF directory.
- The deployment descriptor file is found in the META-INF directory.
- META-INF is not directly accessible to clients.
Given the following deployment descriptor: InitParams com.osborne.c02.InitParamsServlet initParm question14 What is the outcome of running the following servlet? (Choose one.) public class InitParamsServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); PrintWriter out = response.getWriter(); out.write("Initialization Parameter is: " + sc.getInitParameter("initParm")); } }
- A runtime error
- "Initialization Parameter is: null" written to the console
- "Initialization Parameter is: question14" returned to the requester
- "Initialization Parameter is: null" returned to the requester
- "Initialization Parameter is: question14" written to the console
What is the result of loading the web-app with the following deployment descriptor and attempting to execute the following servlet? (Choose two.) author Elmore Leonard public class ContextInitParms extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); Out.write(""); ServletContext sc = getServletContext(); out.write(sc.getInitParameter("auther")); out.close(); } }
- ParameterNotFoundException is thrown.
- Some other exception is thrown.
- "Elmore Leonard" is output on the web page
- An application failure occurs
- null is output on the web page.
- A 404 error occurs in the browser.
Given the following deployment descriptor, identify the sequence of filters that execute on a direct client request for ServletA. (Choose one.) LogFilter ServletA AuditFilter /ServletA FORWARD EncryptionFilter /* ServletA /ServletA
- LogFilter, AuditFilter, EncryptionFilter
- LogFilter, EncryptionFilter
- LogFilter
- EncryptionFilter, AuditFilter, LogFilter
- EncryptionFilter, LogFilter
- AuditFilter, EncryptionFilter, LogFilter