Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views27 pages

Lecture 19

The document contains a series of multiple-choice questions and answers covering various topics in Java, including animation, applets, socket programming, multithreading, servlets, session tracking, JavaServer Pages (JSP), and JavaServer Faces (JSF). Each section includes questions that test knowledge on key methods, classes, and concepts relevant to each topic. The document serves as a study guide for understanding essential Java programming concepts.

Uploaded by

bc230401469mme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views27 pages

Lecture 19

The document contains a series of multiple-choice questions and answers covering various topics in Java, including animation, applets, socket programming, multithreading, servlets, session tracking, JavaServer Pages (JSP), and JavaServer Faces (JSF). Each section includes questions that test knowledge on key methods, classes, and concepts relevant to each topic. The document serves as a study guide for understanding essential Java programming concepts.

Uploaded by

bc230401469mme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Lecture 19: How to Animate?

Q1: Which method is commonly used for redrawing animations in Java?

 repaint() ✅

 draw()

 refresh()

 animate()

Q2: What is the purpose of Thread.sleep(ms) in animations?

 To stop the program

 To pause between frames ✅

 To terminate animation

 To restart animation

Lecture 20: Applets

Q3: Which method is called first in an Applet lifecycle?

 start()

 paint()

 destroy()

 init() ✅

Q4: Which package is required to create an Applet?

 java.swing

 java.awt ✅

 javax.imageio

 javax.swing

Q5: What is the purpose of the paint(Graphics g) method in Applet?

 Initialize UI

 Handle mouse events


 Draw graphics ✅

 Load images

Lecture 21: Socket Programming

Q6: Which class is used to create a server socket in Java?

 Socket

 ServerSocket ✅

 DatagramSocket

 HttpSocket

Q7: Method to accept client request on server side?

 listen()

 waitForClient()

 accept() ✅

 connect()

Q8: Which class is used for client-side communication in socket programming?

 Socket ✅

 ServerSocket

 ClientSocket

 NetworkSocket

Lecture 22: (Content assumed as extension of Networking)

Q9: Which two streams are typically used in socket communication?

 InputStream & OutputStream ✅

 FileReader & FileWriter

 Scanner & Writer

 StreamIn & StreamOut


Lecture 23: Multithreading

Q10: Which method starts the execution of a thread?

 run()

 begin()

 execute()

 start() ✅

Q11: Which interface must be implemented for multithreading?

 Runnable ✅

 Threadable

 Executable

 MainThread

Lecture 24: More on Multithreading

Q12: What does synchronized keyword do?

 Increases speed

 Makes method atomic ✅

 Stops a thread

 Handles exceptions

Q13: Which method pauses a thread temporarily?

 pause()

 wait()

 delay()

 sleep() ✅

Lecture 25: Web Application Development


Q14: Which server is often used to run Java web apps?

 MySQL

 Eclipse

 Apache Tomcat ✅

 NetBeans

Q15: What is a WAR file?

 Windows Application Resource

 Web Archive ✅

 Web Application Runtime

 Web Action Resource

✅ Lecture-wise MCQs: Lectures 26–30

Lecture 26: Java Servlets

Q1: Which method handles HTTP GET requests in a servlet?

 doGet() ✅

 get()

 handleRequest()

 service()

Q2: Which method is called once in a servlet lifecycle?

 destroy()

 init() ✅

 doPost()

 run()

Q3: What package is required for writing a servlet?


 java.io

 javax.servlet ✅

 java.awt

 java.net

Lecture 27: Creating a Simple Web App in Tomcat

Q4: What is the default port of Apache Tomcat?

 80

 8080 ✅

 3306

 8888

Q5: Where are servlets placed in a Tomcat project?

 /html

 /java

 /WEB-INF/classes ✅

 /resources

Lecture 28: Servlet Lifecycle

Q6: Which method is called when the servlet is about to be removed from memory?

 stop()

 close()

 destroy() ✅

 finish()

Q7: The method service() is responsible for:

 Initializing servlet

 Destroying servlet
 Handling requests ✅

 Creating sessions

Lecture 29: More on Servlets

Q8: What is the return type of getServletConfig()?

 ServletInfo

 ServletConfig ✅

 ServletContext

 ConfigObject

Q9: Which method is used to send a redirect response?

 sendRedirect() ✅

 redirectTo()

 forward()

 jump()

Lecture 30: Dispatching Requests

Q10: RequestDispatcher is used for:

 Managing sessions

 Dispatching exceptions

 Forwarding or including resources ✅

 Handling requests directly

Q11: Which method forwards a request to another resource?

 forward() ✅

 include()

 redirect()

 push()
Q12: In RequestDispatcher, which method includes output of another resource?

 forward()

 include() ✅

 attach()

 append()

✅ Lecture-wise MCQs: Lectures 31–35

Lecture 31: Session Tracking

Q1: Which method is used to create a new session in Servlets?

 createSession()

 newSession()

 getSession(true) ✅

 startSession()

Q2: What is t he default timeout for HTTP session in Tomcat?

 5 min

 10 min

 30 min ✅

 60 min

Q3: What is used to identify sessions between requests?

 Cookies ✅

 Threads

 Query strings

 XML

Lecture 32: Session Tracking (Contd.)


Q4: Which object allows session tracking in servlets?

 ServletRequest

 HttpSession ✅

 SessionManager

 RequestDispatcher

Q5: Which method invalidates a session?

 closeSession()

 stop()

 invalidate() ✅

 remove()

Lecture 33: Address Book Case Study (Using Servlets)

Q6: What was the main functionality of the Address Book case study?

 Session handling

 CRUD operations ✅

 Cookie encryption

 User Authentication

Q7: Data in the address book was stored using:

 JSON

 MySQL ✅

 XML

 Files

Lecture 34: JavaServer Pages (JSP)

Q8: JSP stands for:

 Java Servlet Pages


 Java Server Pages ✅

 Java Site Programming

 Java Secure Pages

Q9: JSP files are translated into:

 HTML

 JavaScript

 Servlets ✅

 XML

Q10: What symbol is used to embed Java code in JSP?

 <% %> ✅

 {{ }}

 [[ ]]

 <? ?>

Lecture 35: JavaServer Pages (Contd.)

Q11: Which JSP directive is used to include another file?

 <%@ include ... %> ✅

 <% include ... %>

 <%@ import ... %>

 jsp:include

Q12: What does <jsp:include> do?

 Includes another file at translation time

 Includes content at request time ✅

 Adds Java classes

 Loads external scripts


✅ Lecture-wise MCQs: Lectures 36–40

Lecture 36: (General JSP Review / Implicit Objects)

Q1: Which of the following is NOT a JSP implicit object?

 request

 response

 scanner ✅

 session

Q2: The application implicit object refers to:

 One user session

 One page

 The whole web application ✅

 One servlet

Lecture 37: JSP Action Elements and Scope

Q3: Which scope is available only within a single request?

 request ✅

 session

 page

 application

Q4: Which tag is used to include dynamic resources in JSP?

 <%@ include ... %>

 <jsp:include ... /> ✅

 <jsp:forward ... />

 <jsp:scriptlet ... />

Q5: Scope of a variable declared with application scope?


 Limited to a page

 Available in entire application ✅

 Only inside session

 Only in browser

Lecture 38: JSP Custom Tags

Q6: Custom tags in JSP are defined using:

 JavaBeans

 Tag Libraries ✅

 EL

 JSTL

Q7: TLD file stands for:

 Tag Library Definition ✅

 Template Layout Descriptor

 Tag Level Directive

 Template Library Data

Q8: The purpose of custom tags is to:

 Increase code length

 Replace servlets

 Encapsulate reusable logic ✅

 Handle threads

Lecture 39: MVC + Case Study

Q9: In MVC, the controller is responsible for:

 Displaying data

 Storing data
 Handling requests ✅

 Generating reports

Q10: What is the role of the model in MVC?

 Controls flow

 Stores and manages data ✅

 Handles UI

 Connects to servlet

Q11: The view in MVC is usually implemented using:

 Servlets

 JSP ✅

 Threads

 Databases

Lecture 40: Model 2 Architecture (MVC)

Q12: What is Model 2?

 Thread-based design

 Enhanced version of MVC for web apps ✅

 JavaFX architecture

 Servlet chaining

Q13: In Model 2 architecture, which component processes client input?

 JSP

 Controller (Servlet) ✅

 Model

 Session

Q14: Why is Model 2 preferred?

 Simpler to write
 No need for database

 Separation of concerns ✅

 Faster for desktop apps

✅ Lecture-wise MCQs: Lectures 41–45

Lecture 41: Layers and Tiers

Q1: What does a tier represent in software architecture?

 A visual layer

 A physical separation ✅

 A class type

 A JSP page

Q2: How many main tiers are in multi-tier architecture?

 2

 3 ✅ (Presentation, Business, Data)

 4

 5

Q3: The presentation layer is responsible for:

 Business logic

 Data storage

 User Interface ✅

 Error logging

Lecture 42: Expression Language (EL)

Q4: Expression Language is used in:

 Servlets
 JSP ✅

 JDBC

 Applets

Q5: What symbol is used for EL expressions?

 <% ... %>

 ${ ... } ✅

 {{ ... }}

 << ... >>

Q6: EL provides access to:

 JavaScript

 ServletConfig

 Implicit objects ✅ (like session, request)

Lecture 43: JSTL (JSP Standard Tag Library)

Q7: JSTL stands for:

 Java Servlet Template Library

 Java Server Tag Library

 JavaServer Pages Standard Tag Library ✅

 JSP Servlet Tag List

Q8: Which JSTL tag is used for looping?

 <c:if>

 <c:forEach> ✅

 <c:loop>

 <c:repeat>

Q9: What is the purpose of JSTL?

 Create Java classes


 Write HTML

 Simplify JSP code ✅

 Manage Tomcat

Lecture 44: Client Side Validation & JSF (Intro)

Q10: JavaServer Faces (JSF) is a:

 Database

 UI Framework for Java ✅

 Java compiler

 Thread library

Q11: Client-side validation is performed using:

 Java only

 HTML

 JavaScript ✅

 JSP

Lecture 45: JavaServer Faces (JSF)

Q12: JSF manages UI components using:

 Tag handlers

 Bean containers

 Component tree ✅

 Servlet filters

Q13: What is a "managed bean" in JSF?

 A data controller ✅

 A servlet

 A JSP file
 A database table

Q14: JSF pages typically use file extension:

 .java

 .jsp

 .jsf or .xhtml ✅

 .html

Java Graphics & Animation (Lec 18–20)

1. Which method is used to draw a rectangle in Java Graphics?


→ drawRect(int x, int y, int width, int height) ✅

2. Which method is used to repaint the screen in animation?


→ repaint() ✅

3. What is double buffering in animation?


→ Used to prevent flickering ✅

Applets & Socket Programming (Lec 20–22)

4. Which class is extended to create an applet?


→ javax.swing.JApplet ✅

5. Which method is not part of an Applet life cycle?


→ main() ✅

6. Which class is used for client socket programming?


→ Socket ✅

7. Which method is used to get input from socket?


→ getInputStream() ✅

Multithreading (Lec 23–24)

8. What is the correct way to create a thread?


→ By extending Thread class or implementing Runnable ✅

9. Which method starts a thread?


→ start() ✅
10. Which method causes a thread to pause temporarily?
→ sleep() ✅

Servlets (Lec 26–30)

11. Which method handles GET requests in a servlet?


→ doGet() ✅

12. Servlets are managed by:


→ Servlet container (e.g., Tomcat) ✅

13. Servlet lifecycle begins with:


→ init() ✅

Session Tracking & JSP (Lec 31–35)

14. What object is used for session tracking?


→ HttpSession ✅

15. Which method invalidates a session?


→ invalidate() ✅

16. How to embed Java code in JSP?


→ <% code %> ✅

17. JSP files are compiled into:


→ Servlets ✅

JSP Elements & MVC (Lec 36–40)

18. Which tag is used for request-time inclusion?


→ <jsp:include> ✅

19. What is Model 2 architecture?


→ MVC using Servlets + JSP ✅

20. Which file acts as controller in MVC?


→ Servlet ✅

JSF & JSTL (Lec 41–45)


21. Which tag library provides loop control in JSP?
→ <c:forEach> ✅

22. Expression Language uses what syntax?


→ ${variable} ✅

23. JSF pages use extension:


→ .xhtml ✅

24. Managed beans in JSF are used to:


→ Handle UI logic ✅

1. Which method is used to draw a rectangle in Java Graphics?


A) DrawRect()
B) drawReactangle()
C) drawRect()
D) DrawReactangle()

2. Which method is used to repaint the screen in animation?


A) refresh()
B) redraw()
C) repaint()
D) update()

3. Which class is extended to create an Applet?


A) Applet
B) Panel
C) JApplet
D) Component

4. Which method is not part of an Applet's life cycle?


A) init()
B) start()
C) destroy()
D) main()
5. Which class is used for client socket programming?
A) ServerSocket
B) Socket
C) DataSocket
D) ClientSocket

6. Which method is used to start a thread?


A) run()
B) begin()
C) start()
D) init()

7. How can we create a thread in Java?


A) Implement Runnable
B) Extend Thread
C) Both A & B
D) Use ThreadUtils

8. Which method causes a thread to temporarily pause?


A) wait()
B) pause()
C) sleep()
D) yield()

9. Which method handles HTTP GET requests in a servlet?


A) doPost()
B) doGet()
C) init()
D) service()

10. Which method is used to destroy a servlet?


A) stop()
B) end()
C) destroy()
D) terminate()

11. Which object is used for session tracking in Servlets?


A) Session
B) HttpSession
C) Cookie
D) Request

12. Which method invalidates a session?


A) logout()
B) expire()
C) invalidate()
D) terminate()

13. JSP files are compiled into what?


A) HTML
B) JSP
C) Servlets
D) JavaBeans

14. How do you embed Java code in a JSP file?


A) <%= %>
B) <script> </script>
C) <% %>
D) <?php ?>

15. Which tag includes content at request time?


A) jsp:use
B) jsp:import
C) jsp:include
D) jsp:embed
16. What does TLD stand for in JSP?
A) Tag Level Directive
B) Template Layout Directive
C) Tag Library Descriptor
D) Top Level Declaration

17. What is Model 2 Architecture?


A) Pure JSP
B) MVC using JavaBeans
C) Model 1
D) MVC using Servlets and JSP

18. In MVC, which component handles business logic?


A) View
B) Model
C) Controller
D) JSP

19. What is the scope of request object in JSP?


A) Until session ends
B) Until page reload
C) Until request is processed
D) Forever

20. Which tag loops through a collection in JSTL?


A) <c:loop>
B) <c:repeat>
C) <c:forEach>
D) <c:iterate>

21. Which EL syntax retrieves a variable?


A) @var
B) #{var}
C) ${var}
D) %{var}

22. Which JSF file extension is standard?


A) .jsp
B) .jsf
C) .xhtml
D) .java

23. Which JSF component is used for input?


A) <h:inputField>
B) <h:textInput>
C) <h:inputText>
D) <input>

24. Which class provides metadata of ResultSet?


A) MetaResultSet
B) ResultSetInfo
C) ResultSetMetaData
D) ResultInfo

25. Which collection class allows duplicate elements?


A) HashSet
B) TreeSet
C) ArrayList
D) LinkedHashSet

26. Which JDBC method is used to execute SELECT?


A) executeUpdate()
B) execute()
C) executeSelect()
D) executeQuery()
27. Which class is used to create GUI in Java?
A) JWindow
B) JPanel
C) JFrame
D) JDialog

28. What is used to layout components?


A) UIManager
B) WindowManager
C) LayoutManager
D) GridManager

29. Which method adds a button to a frame?


A) insert()
B) append()
C) add()
D) attach()

30. Which interface handles action events?


A) EventHandler
B) ClickListener
C) ActionListener
D) ButtonListener

31. Which Java keyword is used to inherit a class?


A) inherits
B) extends
C) implements
D) derives

32. Which class can hold key-value pairs?


A) ArrayList
B) Vector
C) HashMap
D) Set

33. Which block is used to catch exceptions?


A) handle
B) catch
C) try
D) except

34. Which object type is thrown for checked exceptions?


A) Throwable
B) RuntimeException
C) Exception
D) Error

35. What is the base class of all exceptions?


A) Exception
B) Throwable
C) Object
D) RuntimeException

36. Which stream reads characters from a file?


A) FileInputStream
B) FileReader
C) InputStream
D) BufferedInputStream

37. Which method is used to check if a ResultSet has more rows?


A) hasNext()
B) next()
C) readNext()
D) isNext()
38. What does MVC stand for?
A) Model Value Controller
B) Model View Connector
C) Model View Controller
D) Monitor View Controller

39. What type of tag is <jsp:useBean>?


A) Scriptlet
B) Directive
C) Action tag
D) Standard tag

40. Which method is called when a servlet is removed?


A) end()
B) stop()
C) close()
D) destroy()

📘 CS506 – Web Design & Development

🎯 Final Term Review – MCQs + Cheat Sheet (Lectures 19–45)

📝 One-Page Summary Cheat Sheet

Graphics & Animation

 repaint(), paint(Graphics g), Applet Lifecycle: init → start → stop → destroy

🔌 Socket Programming

 Socket, ServerSocket, Input/Output Streams

🧵 Multithreading

 Thread, Runnable, synchronized, start(), run()

🌐 Servlets
 init(), service(), destroy(), doGet(), doPost(), RequestDispatcher, HttpSession

📄 JSP – JavaServer Pages

 Scriptlet <% %>, Expression <%= %>, Implicit Objects, Custom Tags

🧩 MVC Architecture

 Model, View, Controller, Model-2 Architecture

🔤 EL & JSTL

 EL: ${}, JSTL tags: <c:forEach>, <c:if>

💡 JSF – JavaServer Faces

 Component-based, Beans, XML config, Navigation rules

📚 MCQs by Lecture Sections (Lectures 19–45)

🔸 Lecture 19–25: Animation, Applets, Sockets, Threads

Q: Which method is called when an applet is first loaded?


A: init()

Q: Which class is used to create server sockets?


A: ServerSocket

Q: What is the correct method to start a thread in Java?


A: start()

🔸 Lecture 26–33: Servlets + Sessions

Q: Which method in servlets handles HTTP GET requests?


A: doGet()

Q: Which interface helps to track sessions in servlets?


A: HttpSession

Q: How can you forward a request from one servlet to another?


A: RequestDispatcher.forward()

🔸 Lecture 34–38: JSP Basics, Tags, Scopes

Q: Which tag in JSP is used to insert Java code?


A: <% code %>

Q: Which object is not an implicit object in JSP?


A: File (others like request, response, out are implicit)
🔸 Lecture 39–41: MVC Architecture

Q: In MVC, what does the Controller do?


A: Handles input and delegates to Model & View

Q: In Model 2, what is used as the controller?


A: Servlet

🔸 Lecture 42–45: EL, JSTL, JSF

Q: What is the syntax for EL to access a variable?


A: ${variable}

Q: What tag library is used for iteration in JSTL?


A: <c:forEach>

Q: JSF is based on what model?


A: Component-based MVC

You might also like