0% found this document useful (0 votes)
6 views36 pages

Document

ML

Uploaded by

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

Document

ML

Uploaded by

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

CS311 Midterm Exam (Weeks 1–8):

Week 1: XML Basics

1. What does XML stand for?

a) Extra Markup Language

b) Extensible Markup Language

c) External Markup Language

d) Execute Markup Language

Answer: b) Extensible Markup Language

2. Which of the following is true about XML syntax?

a) All elements must have a closing tag.

b) XML tags are case-insensitive.

c) Attributes must always have double quotes.

d) An XML document cannot have a DOCTYPE declaration.

Answer: a) All elements must have a closing tag.

3. What is the purpose of a DOCTYPE in XML?

a) Specifies the style of the document

b) Defines the structure and rules of the XML document

c) Ensures case sensitivity


d) Specifies namespaces

Answer: b) Defines the structure and rules of the XML document

Week 2: XML Attributes and Display

4. Which of the following is true about XML attributes?

a) They are used to define the structure of XML.

b) They provide additional information about elements.

c) They are mandatory for all elements.

d) They replace XML elements.

Answer: b) They provide additional information about elements.

5. What is XSLT used for?

a) Defining XML rules

b) Transforming XML documents into other formats like HTML

c) Validating XML documents

d) Defining attributes in XML

Answer: b) Transforming XML documents into other formats like HTML

6. Which XPath expression selects all child nodes of the current node?
a) /child

b) ./

c) //

d) *

Answer: d) *

Week 3: XML Validation and DTD

7. What is the purpose of XML DTD?

a) Styling the XML document

b) Transforming XML into HTML

c) Validating the structure of XML documents

d) Encoding the XML document

Answer: c) Validating the structure of XML documents

8. Which of the following is a valid XML element declaration in DTD?

a) <!ELEMENT note (to, from, heading, body)>

b) <ELEMENT note {to, from, heading, body}>

c) <!ELEMENT note: to, from, heading, body>

d) <!ELEMENT (note) {to, from, heading, body}>

Answer: a) <!ELEMENT note (to, from, heading, body)>


9. What are entities in DTD used for?

a) To represent special characters or reusable content

b) To declare element types

c) To define namespaces

d) To link stylesheets

Answer: a) To represent special characters or reusable content

Week 4: DTD and XML Schema

10. What is the primary advantage of XML Schema over DTD?

a) It supports namespaces.

b) It is simpler to use.

c) It does not validate data types.

d) It cannot define attributes.

Answer: a) It supports namespaces.

11. Which of the following is true about XML DOM?

a) It represents the XML document as a tree structure.

b) It is only used for transforming XML documents.


c) It cannot modify XML data.

d) It does not support node relationships.

Answer: a) It represents the XML document as a tree structure.

12. What does an XML schema use to define the structure of an XML document?

a) Elements and attributes

b) Comments

c) XSLT transformations

d) DOCTYPE declarations

Answer: a) Elements and attributes

Week 5: XML DOM Basics

13. Which object is used to make HTTP requests in XML processing?

a) XMLHttpRequest

b) XMLParser

c) DOMParser

d) HTTPHandler

Answer: a) XMLHttpRequest
14. What is the nodeValue property used for in XML DOM?

a) To get the name of a node

b) To get or set the value of a node

c) To create a new node

d) To traverse nodes

Answer: b) To get or set the value of a node

15. What is a NodeList in XML DOM?

a) A list of element attributes

b) A collection of nodes returned by a query

c) A method to create a new node

d) A function to validate XML

Answer: b) A collection of nodes returned by a query

Week 6: Advanced XML DOM Operations

16. What does the getAttribute() method do?

a) Gets the value of an attribute of an element

b) Sets the value of an attribute of an element

c) Removes an attribute from an element

d) Checks if an attribute exists in an element


Answer: a) Gets the value of an attribute of an element

17. Which method removes a text node in XML DOM?

a) removeChild()

b) removeNode()

c) deleteTextNode()

d) clearNode()

Answer: a) removeChild()

18. What happens when you change an XML node’s value using nodeValue?

a) The attribute name is changed.

b) The node’s content is updated.

c) A new node is created.

d) The node is removed.

Answer: b) The node’s content is updated.

Week 7: XML DOM – Creating and Replacing Nodes

19. Which method is used to create a new element node?

a) createNode()
b) createElement()

c) newNode()

d) appendChild()

Answer: b) createElement()

20. What is the purpose of the appendChild() method?

a) Removes a child node from an element

b) Appends a child node to an element

c) Replaces the content of a node

d) Updates an attribute of a node

Answer: b) Appends a child node to an element

21. What is a CDATA section used for in XML?

a) To include comments

b) To escape blocks of text containing characters like < and &

c) To store attribute information

d) To define element relationships

Answer: b) To escape blocks of text containing characters like < and &

Week 8: Inserting and Cloning Nodes


22. What does the cloneNode() method do in XML DOM?

a) Duplicates an existing node

b) Moves a node to a different location

c) Creates a new empty node

d) Deletes the original node

Answer: a) Duplicates an existing node

23. Which method is used to insert a node at a specific position?

a) appendChild()

b) insertBefore()

c) replaceChild()

d) createNode()

Answer: b) insertBefore()

24. What happens when you use setAttribute() in XML DOM?

a) Creates a new attribute or updates an existing attribute

b) Removes an attribute from an element

c) Gets the value of an existing attribute

d) Appends an attribute to a node list

Answer: a) Creates a new attribute or updates an existing attribute

Here are MCQs covering Module 1 to Module 9 as per your request:


Module 1: Object-Oriented Paradigm

1. What is the primary focus of object orientation in programming?

a) Functions

b) Objects

c) Variables

d) Algorithms

Answer: b) Objects

2. Which principle allows a programmer to hide irrelevant details about an object?

a) Polymorphism

b) Inheritance

c) Abstraction

d) Encapsulation

Answer: c) Abstraction

3. What is an example of the ‘is-a’ relationship in inheritance?

a) Car “is-a” Vehicle

b) Tree “is-a” Branch

c) Dog “is-a” Color

d) House “is-a” Room

Answer: a) Car “is-a” Vehicle


Module 2: Basics of Java Programming

4. What is the default value for a boolean instance variable in Java?

a) true

b) false

c) null

d) 0

Answer: b) false

5. Which of the following keywords is used to declare a constant in Java?

a) static

b) final

c) const

d) immutable

Answer: b) final

6. What does the static keyword in Java indicate?

a) A method or variable that belongs to the class, not the instance

b) A variable with fixed memory

c) A method that cannot be overridden


d) A variable that cannot be changed

Answer: a) A method or variable that belongs to the class, not the instance

Module 3: Program Control Flow

7. Which control flow statement is used to break out of a loop?

a) continue

b) break

c) return

d) exit

Answer: b) break

8. Which looping construct evaluates its condition at the bottom of the loop?

a) For loop

b) While loop

c) Do-while loop

d) Nested loop

Answer: c) Do-while loop

9. What does the following code print?


For (int I = 0; I < 3; i++) {

System.out.print(I + “ “);

a) 0 1 2

b) 0 1 2 3

c) 1 2 3

d) 1 2

Answer: a) 0 1 2

Module 4: Using Objects

10. Which of the following is NOT a characteristic of an object in Java?

a) State

b) Behavior

c) Identity

d) Class

Answer: d) Class

11. What keyword is used to create an object in Java?


a) create

b) new

c) object

d) instance

Answer: b) new

12. What is encapsulation also referred to as?

a) Data hiding

b) Functionality inheritance

c) Object sharing

d) Code reusability

Answer: a) Data hiding

Module 5: Primitive Values as Objects

13. Which class is used to represent primitive values as objects?

a) Wrapper classes

b) String class

c) Object class

d) Primitive class

Answer: a) Wrapper classes


14. Which of these is the correct way to convert an int to an Integer in Java?

a) int I = 5; Integer obj = Integer.valueOf(i);

b) int I = 5; Integer obj = new Integer(i);

c) Both a and b

d) Neither a nor b

Answer: c) Both a and b

15. What is the value of the following code?

Integer x = Integer.valueOf(“123”);

System.out.println(x);

a) 123

b) 0

c) Error

d) Null

Answer: a) 123

Module 6: Arrays
16. How are arrays stored in memory in Java?

a) Statically

b) Dynamically

c) Sequentially

d) Randomly

Answer: c) Sequentially

17. What is the default value of an array of int in Java?

a) 0

b) null

c) -1

d) Undefined

Answer: a) 0

18. Which method is used to determine the length of an array in Java?

a) length()

b) size()

c) length

d) getSize()

Answer: c) length
Module 7: Classes

19. What is the blueprint for creating objects in Java?

a) Object

b) Class

c) Method

d) Constructor

Answer: b) Class

20. Which of these is true about constructors in Java?

a) They have a return type.

b) They must have the same name as the class.

c) They can be called directly like a method.

d) They cannot be overloaded.

Answer: b) They must have the same name as the class.

21. What is the purpose of the this keyword in Java?

a) To refer to the current object

b) To refer to the superclass

c) To call a static method

d) To declare a variable

Answer: a) To refer to the current object


Module 8: Object Communication

22. Which of these mechanisms is used for object communication?

a) Methods

b) Variables

c) Inheritance

d) Polymorphism

Answer: a) Methods

23. What happens when an object is passed as a parameter in Java?

a) A new copy of the object is created.

b) The reference to the object is passed.

c) Only the variables are passed.

d) The object is converted to primitive types.

Answer: b) The reference to the object is passed.


Module 9: Modifiers

24. Which access modifier allows a member to be visible only within its class?

a) Public

b) Protected

c) Private

d) Default

Answer: c) Private

25. Which modifier is used to prevent a method from being overridden?

a) static

b) final

c) abstract

d) public

Answer: b) final

26. What does the protected access modifier allow?

a) Access from the same class only

b) Access from the same package and subclasses

c) Access from anywhere

d) Access from the same method only

Answer: b) Access from the same package and subclasses


Here are the MCQs from Module 9 to Module 19 as per the document content:

Module 9: Modifiers

1. What is the main purpose of the final keyword in Java?

a) To create a constant variable

b) To prevent method overriding

c) To prevent class inheritance

d) All of the above

Answer: d) All of the above

2. Which modifier allows visibility only within the same package?

a) public

b) private

c) protected
d) default

Answer: d) default

3. What is the effect of declaring a class as abstract?

a) It cannot be instantiated.

b) It must contain at least one abstract method.

c) It is immutable.

d) Both a and b.

Answer: d) Both a and b

Module 10: Exception Handling

4. Which block in Java must always accompany a try block?

a) catch

b) finally

c) throws

d) Either a or b

Answer: d) Either a or b

5. What is the purpose of the throw keyword in Java?


a) To explicitly raise an exception

b) To handle an exception

c) To ignore an exception

d) To specify the exceptions a method can throw

Answer: a) To explicitly raise an exception

6. Which exception is thrown when an array index is accessed out of its bounds?

a) ArrayIndexOutOfBoundsException

b) ArithmeticException

c) NullPointerException

d) IOException

Answer: a) ArrayIndexOutOfBoundsException

Module 11–13: XML, XML DOM, and JAXP

7. What does XML stand for?

a) Extra Markup Language

b) Extensible Markup Language

c) External Markup Language

d) Executable Markup Language

Answer: b) Extensible Markup Language


8. Which of the following is a valid use of XML?

a) Data transport

b) Configuration files

c) Web services

d) All of the above

Answer: d) All of the above

9. Which interface is used to parse XML documents in DOM?

a) DocumentBuilder

b) SAXParser

c) DOMParser

d) XMLBuilder

Answer: a) DocumentBuilder

10. What is the role of JAXP in Java?

a) Parsing and transforming XML documents

b) Storing XML data

c) Designing XML schemas

d) Querying XML databases

Answer: a) Parsing and transforming XML documents


Module 14: Introduction to JAXP

11. Which package provides the classes and interfaces for JAXP?

a) javax.xml.parsers

b) javax.xml.validation

c) javax.xml.transform

d) All of the above

Answer: d) All of the above

12. Which parser in JAXP is event-driven and faster?

a) DOM parser

b) SAX parser

c) StAX parser

d) Pull parser

Answer: b) SAX parser

Module 15: Servlets


13. Which method is used to handle HTTP POST requests in servlets?

a) doPost()

b) doGet()

c) service()

d) init()

Answer: a) doPost()

14. What is the default port for HTTP requests handled by servlets?

a) 443

b) 21

c) 80

d) 8080

Answer: c) 80

15. Which object in servlets is used to read client data sent as part of the request?

a) HttpServletRequest

b) HttpServletResponse

c) ServletConfig

d) ServletContext

Answer: a) HttpServletRequest
Module 16: Java Database Connectivity (JDBC)

16. Which driver type in JDBC is known as the “pure Java” driver?

a) Type 1

b) Type 2

c) Type 3

d) Type 4

Answer: d) Type 4

17. Which method is used to execute an SQL query in JDBC?

a) executeUpdate()

b) executeQuery()

c) executeStatement()

d) runQuery()

Answer: b) executeQuery()

18. What is the purpose of the Connection interface in JDBC?

a) To establish a connection with the database

b) To execute SQL commands

c) To retrieve database metadata

d) To close the connection

Answer: a) To establish a connection with the database

Module 17: Introduction to Web Services


19. Which protocol is commonly used for Web Services?

a) HTTP

b) FTP

c) SMTP

d) SNMP

Answer: a) HTTP

20. What is the key difference between SOAP and REST Web Services?

a) SOAP is stateless; REST is stateful

b) SOAP uses XML; REST can use XML or JSON

c) REST is tightly coupled; SOAP is loosely coupled

d) SOAP does not support HTTP

Answer: b) SOAP uses XML; REST can use XML or JSON

Module 18: Web Services Architecture

21. Which of these is NOT a component of Web Services Architecture?

a) Service provider

b) Service registry

c) Service requester

d) Service gateway

Answer: d) Service gateway

22. What is the role of WSDL in Web Services?

a) It provides the service definition.


b) It stores service logs.

c) It registers the service provider.

d) It secures the web service.

Answer: a) It provides the service definition.

Module 19: Web Services with JAX-WS

23. What is JAX-WS used for in Java?

a) Building RESTful web services

b) Building SOAP-based web services

c) Parsing XML documents

d) Securing web services

Answer: b) Building SOAP-based web services

24. Which annotation is used to define a web service endpoint in JAX-WS?

a) @WebService

b) @Service

c) @SOAPService

d) @Endpoint

Answer: a) @WebService

25. What is the default communication protocol used by JAX-WS?

a) FTP

b) HTTP

c) SMTP
d) TCP

Answer: b) HTTP

Here are concise short answers to the syllabus topics from the handouts:

Week 1: Introduction to XML

1. What is XML?

XML (Extensible Markup Language) is a markup language designed to store and transport
data, focusing on simplicity and usability across systems.

2. The Syntax of XML

XML tags are case-sensitive.

All elements must have closing tags.

Tags must be properly nested.

An XML document must have a root element.


3. The Rules of XML

Tags must match case and order.

Attribute values must be quoted.

There should be no overlapping tags.

4. What is DOCTYPE?

DOCTYPE declares the type of document and its DTD (Document Type Definition) to define
rules and structure.

Week 2: Advanced XML Concepts

5. What are XML Attributes?

XML attributes provide additional information about elements but are not preferred for
storing complex data.
6. What are XML Namespaces?

XML Namespaces prevent naming conflicts by providing unique names using a URI.

7. What is XML Encoding?

XML encoding specifies the character set (e.g., UTF-8 or ISO-8859-1) used in the
document.

8. What is XSLT?

XSLT (Extensible Stylesheet Language Transformations) is used to transform XML data into
other formats like HTML or plain text.

9. What is XPath?

XPath is a language for navigating and querying nodes in an XML document using
expressions.

Week 3: XML Validation and DTD

10. What is XML Validator?

An XML Validator checks the document for well-formedness and validity against a DTD or
Schema.
11. What are XML DTD Building Blocks?

Elements: Define the structure.

Attributes: Provide metadata.

Entities: Represent reusable content.

12. What are the types of DTD entities?

General entities: Replaceable text.

Parameter entities: Used in DTD files.

Week 4: DTD and XML Schema

13. What is XML Schema?


XML Schema defines the structure and data types of an XML document using elements and
attributes.

14. What is XML DOM?

XML DOM (Document Object Model) represents the structure of an XML document as a
tree of nodes.

15. How can you load an XML document in DOM?

From a file: Using load().

From a string: Using loadXML().

Week 5: Working with XML DOM

16. What is the XMLHttpRequest Object?

XMLHttpRequest is an API for sending and receiving data from a server asynchronously.
17. What are Node Types in XML DOM?

Element Node: Represents an element.

Attribute Node: Represents an attribute.

Text Node: Represents text within an element.

18. What is the Node List?

A Node List is a collection of nodes, such as child nodes of a given parent element.

Week 6: XML DOM Operations

19. How can you get the value of an attribute in XML DOM?

Use the getAttribute() method.

20. How do you remove a node in XML DOM?

Use the removeChild() method on the parent node.


21. What is the use of nodeValue?

It gets or sets the value of a text node or attribute.

Week 7: Creating and Modifying Nodes

22. How do you create a new element in XML DOM?

Use the createElement() method.

23. What is appendChild() used for?

Appends a new node as the last child of a specified node.

24. How do you create a comment node?

Use the createComment() method.

Week 8: Inserting and Cloning Nodes


25. How do you insert a node in XML DOM?

Use the insertBefore() method to insert a node at a specific position.

26. What is the purpose of cloneNode()?

It creates a copy of an existing node, with or without its child nodes.

27. How can you add a new attribute to an element?

Use the setAttribute() method.

Let me know if you need further explanations or more details!

You might also like