Srikanth Technologies

Assignments for Lectures in Building Web Applications Using Java EE at Udemy.com

4. Introduction to JDBC

  1. JDBC API is provided by _____________.
  2. JDBC Driver is provided by ______________.
  3. JDBC API is to be implemented by JDBC Driver. True/False
  4. Some databases provide multiple JDBC Drivers. True/False

5. Connecting to MySQL database

  1. ____________ method of DriverManager is used to connect to database.
  2. ____________ is the object used to represent a connection to database.
  3. ____________ method is used to disconnect from database.

6. Executing DML Commands

  1. DML stands for _________________.
  2. Accept job id and new minimum salary and update JOBS table.
  3. Accept job id and delete job with given id. Display error message if job id is not found.

7. Executing Query

  1. ________ method is used to move to next record in ResultSet.
  2. If SELECT command retrieves no row, will it be an exception? True/False
  3. Accept job id and display details of employees who are doing that job.
  4. Accept salary from user and display employees whose salary is less than the entered salary.

8. JDBC API vs. JDBC Driver

  1. ________ interface represents a connection to database.
  2. DriverManager.getConnection() returns an object of a class implementing Connection interface. True/False
  3. JDBC driver is a collection of classes that provide their own API. True/False

9. Types of JDBC Drivers

  1. How many types of JDBC drivers do we have?
  2. If a database has no JDBC driver then we can't access it at all. True/False
  3. ________ type of driver depends on native API.
  4. ________ type of driver(s) can be used without using anything native.

10. Transaction Management

  1. __________ method of connection object is used to start transaction.
  2. Once a transaction is committed, it can't be rolled back. True/False
  3. By default JDBC starts a new transaction and commits all changes as and when we execute DML command. True/False
  4. If we start a transaction and then close connection then transaction is ______________ [committed/rolled back]

11. Using RowSet

  1. __________ rowset is used to select data based on given predicate.
  2. __________ method of RowSet is used to move to first row.
  3. Can we update rows in RowSet?
  4. Which method is used to insert a new row into a RowSet?

12. Introduction To Web Application Architecture

  1. Java EE is an example for __________ side scripting.
  2. _________ protocol is used to make request in web applications.
  3. _______ is the language used for client-side scripting.
  4. ________ from google can be used to build front-end of web applications.

13. Creating a Web Application

  1. Which folder in Eclipse project contains HTML files?
  2. _________ is the type of project we have to create for Java EE web application in Eclipse.
  3. _________ is the default port number at which Tomcat runs.
  4. The name of the project is used in URL to access components in the project. True/False

14. Creating Servlets and Receiving Data from Client

  1. ________ annotation is used to specify the URL associated with Servlet.
  2. ________ method of Servlet is invoked when Http Get request is made from client.
  3. ________ method of HttpServletRequest object is used to read parameters passed from client.
  4. ________ tag is used to create a textbox in HTML form.
  5. ________ attribute of HTML form is used to specify the servlet to be invoked.
  6. Create a Servlet that sends a random quote every time it is invoked.
  7. Create a Servlet that takes a number as request parameter and displays its factors as bullets.

15. Difference between GET and POST requests

  1. Data sent using GET request is passed through querystring. True/False
  2. Which attribute of HTML form is used to specify that POST request is to be made?
  3. Which part of HTTP request contains data when POST request is made?
  4. Create HTML form to take age and weight from user and send it to a Servlet that displays BMI of the person.
  5. Create Servlet that takes 4 letter PIN from user using POST request and display whether it is valid input. Input is considered to be valid if it has 4 digits. Make sure input is not visible to user at the time of entering it.

16. Servlet API and Servlet Life Cycle

  1. ___________ is the interface every Servlet must implement.
  2. Which method in Servlet is called at the time of initializing Servlet?
  3. Which method is called just before Servlet is removed from memory?
  4. How do we create a Servlet without using @WebServlet annotation?
  5. Create a Servlet that stores in a list all the numbers passed to it from request parameter number. Design it in such a way it displays all numbers sent to it when it is invoked with parameter display.
  6. How do we pass parameters to Servlet at the time of initializing it?

17. Uploading Files from Client to Server

  1. ___________ method is used in Servlet to get access to file uploaded from client.
  2. ___________ control in HTML form is used to send file to server.
  3. Method getRealPath() is present in ______________ interface.
  4. What is physical path in web application and how it is different from virtual path?
  5. Create a Servlet that takes a text file from client and displays all unique words as bullets.

18. Accessing File System from Servlet

  1. Can we access file system of client making request from Servlet?
  2. In order to access folder where web application is deployed, we need to use _______________ method.
  3. When sending response to client, can we use physical path for HREF and SRC attributes of HTML tags?
  4. Create a Servlet that takes file names.txt in data folder in root directory of web application and display all names in sorted order. Assume names.txt contains one name per line.

19. Creating JSPs

  1. ___ and _____ characters are used to enclose Java code in JSP.
  2. Can a JSP have multiple scriptlets?
  3. A JSP should be considered when we have more HTML to send to client and less Java code to execute. True/False
  4. Create a JSP that takes a number and length from client and displays math table for the number upto the given length in the form of HTML table.
  5. Create a JSP that displays first 20 Fibonacci numbers.

20. Life Cycle of JSP

  1. ________ method in JSP is equivalent to init() method in Servlet.
  2. Whenever you run JSP, web container compiles it to bytecode. True/False
  3. Can we say JSPs are as efficient as Servlet when it comes to execution time?
  4. When we declare variables using JSP declaration, are variable placed inside a method or at the class level?
  5. Create a JSP that displays messages when it is initialized and destroyed.

21. Accessing MySQL database from JSP

  1. ________ folder in web application contains JDBC driver (.jar file).
  2. ________ method is used to load JDBC driver and make it available to web application.
  3. ________ property of page directive is used to import packages and classes in JSP.
  4. Create a JSP to display top 5 highest salaried employees.
  5. Create a JSP to take job id as request parameter and display all employees with that job id.

22. Using JavaBeans

  1. A JavaBean must have a constructor with ________ number of parameters.
  2. __________ must be name of the method used to change the value of property amount.
  3. When setProperty tag is used to assign values to JavaBean properties, which properties are considered?
  4. What are available scopes for JavaBean?
  5. Create a JavaBean with id and salary as properties and use this to update salary of employee.
  6. Create a JavaBean to insert a new row into JOBS table.

23. Redirection and Navigation

  1. What is the difference between forward() and include()?
  2. What is the difference between client-side redirection and server-side redirection?
  3. __________ can be used with forward action to pass additional parameters to target URL.
  4. If we have to send an object of Customer class from one JSP to another while using forward action, where do we place the object?
  5. How do you write code to redirect to morning.jsp if hour of the day is before 12 otherwise evening.jsp?

24. Expression Language

  1. ______ is the expression to access value of parameter amount.
  2. What happens if we try to access a parameter in EL that is not present in the request parameters?
  3. Can we use EL in scriptlet?
  4. How do we refer to property price of JavaBean with id product in EL?
  5. ___________ is used to access value of user attribute of request object in EL?

25. Cookies

  1. When expiry date is not set for a cookie then cookie is called as ___________.
  2. Cookie is sent back to server with every request from client. True/False
  3. __________ method is used to get all cookies coming from client.
  4. Write a JSP to display the value of cookie with name user if it is present otherwise redirect user to login.jsp page.

26. Sessions

  1. What is session timeout?
  2. A session can be used to store data on the server about each client separately. True/False.
  3. ___________ method can be used to remove an attribute from session.
  4. ___________ method is used to terminate current session programmatically.
  5. Create a JSP to display session id and all attributes in the session.
  6. Create a JSP to copy all session attributes to application attributes.
  7. Create a session attribute that stores last access datetime for a JSP and displays it everytime JSP is invoked.

27. Using JSTL Core Tags

  1. __________ attribute of forTokens tag is used to specify separator.
  2. How do we create an attribute in application object using set tag?
  3. Using ______, __________ and __________ tags is similar to using switch statement.
  4. What is the purpose of escapeXml attribute of out tag?
  5. _________ tag is used to store exception raised in a block of code.
  6. Write code using core tags to display all request attributes.
  7. Write code using core tags to redirect to login.jsp if auth cookie is not found in request.

28. Using JSTL SQL and XML Tags

  1. _______ tag is used to execute a query.
  2. _______ is the return type of getRowsByIndex() method of Result interface.
  3. Which method is used to get column names for the result of a query?
  4. _______ attribute of update tag is used to obtain count of rows updated.
  5. Create a JSP to display all rows and columns of the table whose name is passed as a parameter.
  6. Create a JSP that inserts a row into JOBS table with values passed through request parameters.

29. Making AJAX Calls

  1. Which object of browser is used to make asynchronous request?
  2. Using AJAX can update a part of the page without having to redraw complete page. True/False
  3. Which method of jQuery is used to make AJAX request?
  4. Create HTML page to take employee id and new salary and send that data to updateSalary.jsp using AJAX request. Ensure updateSalary.jsp sends empty text on success and error message on error.

30. Sending JSON from Server

  1. _______ method of Gson is used to convert given object to JSON.
  2. How do we convert a CachedRowSet to an array of JSON object?
  3. Create an HTML page that makes AJAX request to jobs.jsp whenever user clicks on a button and displays the data in a table. Send data in JSON format from jobs.jsp.
  4. Create jobs.jsp to send jobs details as an array of JSON object. Call jobs.jsp from HTML page using AJAX and display job title as text and job id as value in a dropdownlist.

31. Listeners

  1. ________ method in ServletContextListener is called when application is being shutdown.
  2. How do we access session in sessionCreated() method?
  3. Create a listener that stores list of names in Application object by taking names from names.txt file in root directly of web application.
  4. Create a listener that writes to server console the date and time of each session's creation and termination.

32. Filters

  1. ________ is annotation to create a Filter.
  2. Is it possible to associate a filter with only .html pages?
  3. Create a filter that checks whether attribute user is present in session and if not present then redirects to login.jsp. Make sure it allows login.jsp to be called even though user is not present in session.

33. Deploying Web Application

  1. ________ folder of Tomcat contains all web applications.
  2. ________ folder contains all .jar files required by application.
  3. A .war file contains all files related to web application including .jar files. True/False
  4. All Servlets and JavaBeans are eventually converted to .class files. True/False