2017 Enterprise Architecture Scheme

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Higher National Diploma in Information Technology

Second year, Second Semester Examination – 2017


HNDIT2411 - Enterprise Architecture – Model Answer

Instructions for Candidates: No. of questions: 06


Answer only 05 questions. No. of pages : 04
Time : 03 hours

1. (Total 20 Marks)
i. What is “Enterprise Computing”? (03 marks)
Computing that is distributed across the network which support the need to build
distributed, transactional, and portable applications that leverage the speed, security,
and reliability of server side technology.
ii. Briefly explain levels of the 3-tiered architecture using a suitable diagram.
(08 marks)
2 marks

JavaEE Application
Server

Web application

Web browser

Business
Logic
Database

Standalone
Application

Client tier Middle tier Data tier

2 *3 Marks
Client tier - client program makes requests to middle tier
Middle tier - handles client requests by processing
application data (business logic – business tier)
Data tier - persistent data store (database / legacy system / etc.)
iii. What is a J2EE component? Give two examples. (04 marks)
Self-contained functional software unit that is assembled into a J2EE application with its
related classes and files and that communicates with other components.
Eg: servlets, Java server pages, Javabeans, Enterprise Javabeans etc.

iv. Briefly explain the term Web Application Framework. Give two examples for Java
Web Application Frameworks. (05 marks)
3 Marks
Web application framework (WAF) is a software framework that is designed to support the
development of web applications including web services, web resources, and web APIs. Web
frameworks provide a standard way to build and deploy web applications.
Example (1*2 Marks )
Spring, JSF, GWT, Grails, Struts, Dropwizard, JHipster, jax-rs, Vaadin, Seam, Wicket,
Tapestry etc

2. (Total 20 Marks)
i. What is concurrency? (03 marks)
Concurrency is the ability to run several programs or several parts of a program in
parallel.
ii. How to implement Threads in java? Explain each method using Java code segments.
(08 marks)
2 ways
1. By extending the Thread class
public class HelloThread extends Thread {
public void run() {
System.out.println("Hello from a thread!");
}

HNDIT 2 Enterprise Architecture 2017


2
public static void main(String args[]) {
(new HelloThread()).start();
}

2. By implementing the Runnable interface


public class HelloRunnable implements Runnable {

public void run() {


System.out.println("Hello from a thread!");
}

public static void main(String args[]) {


(new Thread(new HelloRunnable())).start();
}

iii. Briefly explain the importance of thread synchronization in Java. (03 marks)
Thread synchronization, coordinates access to shared data by multiple concurrent
threads.
Ensures that each thread accessing a shared object excludes all other threads from
doing so simultaneously.
iv. Java provides two approaches in scheduling threads. What are they? Briefly explain
each. (06 marks)
Preemptive
The highest priority task executes until it enters the waiting or dead states or a
higher priority task comes into existence. (Thread.setPriority( int priority)

HNDIT 2 Enterprise Architecture 2017


3
Time slicing
A task executes for a predefined slice of time and then reenters the pool of ready
tasks.

3. (Total 20 Marks)
i. What is a JDBC driver? (02 marks)
Set of classes that interface with a specific database engine.
ii. The following Java programme performs a simple query on the DreamHome database. It
retrieves all the data in the Product table and displays them. Fill the blanks with suitable
Java codes. (09 marks)
import java.sql.*;
public class viewProducts{
static final String url=("jdbc:mysql://localhost/Dreamhome","root"," ");
String sql = "SELECT product_ID, description, unit FROM Product";
public static void main(String[] args) {
try{
// Load JDBC driver
a. ………………………………………………………………
// Make connection
b. ………………………………………………………………

// Create statement
c. ………………………………………………………………
// Execute query
d. ………………………………………………………………
// Process the result
e. ………………………………………………………………
f. ………………………………………………………………
//Ensure connection, statement, result set are closed.

HNDIT 2 Enterprise Architecture 2017


4
g. ………………………………………………………………
h. ………………………………………………………………
i. ………………………………………………………………
} catch (SQLException e) {
System.out.println(e);
}}}
Modal Answer (1*9 marks)
import java.sql.*;
public class viewProducts{
static final String url= " "jdbc:mysql://localhost/Dreamhome","root"," "";
String sql = "SELECT product_ID, description, unit FROM Product";
public static void main(String[] args) {
try{
// Load JDBC driver
j. Class.forName("com.mysql.jdbc.Driver");
// Make connection
k. Connection con=DriverManager.getConnection(url);
// Create statement
l. Statement stmt=con.createStatement();
// Execute query
m. ResultSet rs=stmt.executeQuery(sql);
// Process the result
n. while(rs.next())
o. System.out.println(rs.getString(1)+" "+rs.getString(2)” "+rs.getString(3);
//Ensure connection, statement, result set are closed.
p. stmt.close();
q. rs.close();
r. con.close();
}
}

HNDIT 2 Enterprise Architecture 2017


5
iii. The PreparedStatement object allows to execute parameterized queries. Demonstrate
above statement with suitable code fragment. [ consider that the user supplies the
product_ID and wants to see the details of that product ] (04 marks)
String sql =
" SELECT product_ID, description, unit FROM Product WHERE product_ID = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, UsergivenProductID);
- In the above sql statement the product ID is not given. It can be passed to the
statement after getting from the value from the user as shown.

iv. What is Hibernate? What are the advantages of Hibernate over JDBC?
(05 marks)
- Hibernate is java based ORM (Object-relational mapping) tool that provides
framework for mapping application domain objects to the relational database tables
and vice versa. (03 Marks)
- Advantages (02 Marks for any correct advantage)
• Hibernate is data base independent, same code will work for all data bases like
ORACLE,MySQL ,SQLServer etc. In case of JDBC query must be data base specific.
• As Hibernate is set of Objects, you don't need to learn SQL language.
You can treat TABLE as a Object. In case of JDBC you need to learn SQL.
• Hibernate removes a lot of boiler-plate code that comes with JDBC API, the code
looks cleaner and readable.
• Hibernate supports inheritance, associations and collections. These features are not
present with JDBC API.

4. (Total 20 Marks)
i. What is an XML parser? Give two (02) examples for Java XML parsers. (04 marks)
A XML parser is a program that reads a XML document, checks whether it is
syntactically correct, and takes some actions as it processes the document.

HNDIT 2 Enterprise Architecture 2017


6
Eg: Sun JAXP, IBM XML4J, Apache Xerces, Resin (Caucho), DXP (DataChannel),
Sun JAXP, SAXON
ii. Write the XML code that describes the given scenario. (08 marks)
The root element is CATALOG. The root element may contain no CATEGORY
element or one CATEGORY element along with any number of BOOK elements.
The BOOK element must contain each of the following items AUTHOR, TITLE,
PRICE, and PUBLISH_DATE respectively. The BOOK element may contain an
attribute called "LANGUAGE" which may have either a value of "Sinhala",
"English", or "Tamil". The elements AUTHOR, TITLE, PRICE and
PUBLISH_DATE all contain PCDATA which is parsed character data.
< CATALOG >
< CATEGORY >Computer Books</ CATEGORY >
< BOOK >
< AUTHOR > xxxxxx </ AUTHOR >
< TITLE > xxxx </ TITLE >
< PRICE > xxxxxx </ PRICE >
< PUBLISH_DATE > xxxxxx </ PUBLISH_DATE >
< /BOOK >
< BOOK Language = “Sinhala” >
< AUTHOR > xxxxxx </ AUTHOR >
< TITLE > xxxx </ TITLE >
< PRICE > xxxxx </ PRICE >
< PUBLISH_DATE > xxxxx </ PUBLISH_DATE >
</ BOOK >
</ CATALOG >

HNDIT 2 Enterprise Architecture 2017


7
iii. Write the Document Type Definition (DTD) file for the above XML document.
(08 marks)
<!DOCTYPE CATALOG [

<!ELEMENT CATALOG (CATEGORY?, BOOK *)>


<!ELEMENT CATEGORY (#PCDATA)>
<!ELEMENT BOOK (AUTHOR, TITLE, PRICE, PUBLISH_DATE)+>
<!ATTLIST BOOK LANGUAGE (Sinhala | English | tamil) #IMPLIED>
<!ELEMENT AUTHOR (#PCDATA)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
<!ELEMENT PUBLISH_DATE (#PCDATA)>

]>

5. (Total 20 Marks)
i. What is Servlet container? Name three common tasks performed by Servlet
Container? (05
marks)
Model Answer [2 Marks]
Servlets run inside a special container called the servlet container as part of the same
process as the web server itself. It is an application server that provides the facilities for
running Java servlets
The servlet container is responsible for initializing, invoking, and destroying each servlet
instance.

Model Answer [1 * 3 Marks]

Common tasks of the servlet container:


• Creating the Request Object.
• Creating the Response Object.
• Invoking the service method of the servlet, passing the request and response objects.

HNDIT 2 Enterprise Architecture 2017


8
• Communication Support.
• Lifecycle and Resource Management
• Multithreading Support
• JSP Support
• Miscellaneous Task: Servlet container manages the resource pool, perform memory
optimizations, execute garbage collector, and provides security configurations, support
for multiple applications, hot deployment and several other tasks behind the scene that
makes a developer life easier.

ii. Write JSP code segment to create a function to calculate and print the cube of a given
number. Use JSP scriplets. . (05 marks)
<%!
int cube(int n){
return n*n*n*;
}
%>

<%= "Cube of 5 is: " +cube(5) %>

iii. Name the four methods of session management in Servlets? (04 marks)
o Cookies are small files that the servlet can store on the client computer, and
retrieve later
o URL rewriting: You can append a unique ID after the URL to identify the user
o Hidden <form> fields can be used to store a unique ID
o Java’s Session Tracking API can be used to do most of the work for you

iv. The following index.html file has been provided to a user to input an integer.
<html>
<body>
<form action="NumServlet" method = "get">

HNDIT 2 Enterprise Architecture 2017


9
Enter number: <input type="number" name="value"> <br/>
<input type="submit" value="search"/>
</form>
</body>
</html>
Write the code for Java Servlet which collects the number from the HTML form and
displays the numbers from zero to the number entered by the user. (06 marks)

import java.io.*;
import javax.servlet.*; 02 Marks
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet 02 Marks
{
02 Marks
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>"); 04 Marks
out.println("<BIG>Hello World</BIG>");
out.println("</BODY>");
String num = request.getParameter("value");
int n = Integer.parseInt(num);
for (int i=0; i<=n; i++)
out.println(i);
out.println("</HTML>");
}
}

HNDIT 2 Enterprise Architecture 2017


10
6. (Total 20 Marks)
i. What is an Enterprise Bean? Briefly describe the two categories of Enterprise Beans.
(08 marks)
An enterprise bean is a server-side component that encapsulates the business logic of an
application. (02 marks)
Session Beans
A session bean encapsulates business logic that can be invoked programmatically by a
client over local, remote, or web service client views.
Message-Driven Bean
A message-driven bean is an enterprise bean that allows Java EE applications to process
messages asynchronously.

ii. Write short notes on the followings: (3 * 4 marks)


a. Web Services
• A web service is any piece of software that makes itself available over the internet
and uses a standardized XML messaging system.
• XML is used to encode all communications to a web service.
• As all communication is in XML, web services are not tied to any one operating
system or programming language--Java can talk with Perl; Windows applications
can talk with Unix applications.
b. Service oriented architecture
• An architectural style of building software applications that promotes loose
coupling between components so that you can reuse them and work within a
distributed systems architecture
• This architecture has been wide-accepted
• Some SOA product has been built by Oracle (SOA Suite), IBM(Websphere),
Microsoft(BizTalk)

HNDIT 2 Enterprise Architecture 2017


11
c. SOAP
• SOAP stands for Simple Object Access Protocol.
• It is a XML-based protocol for accessing web services.
• SOAP is a W3C recommendation for communication between two applications.
• SOAP is XML based protocol. It is platform independent and language
independent. By using SOAP, you will be able to interact with other programming
language applications.

d. Java annotations
• Annotations, a form of metadata, provide data about a program that is not part of
the program itself. Annotations have no direct effect on the operation of the code
they annotate.
• Annotations have a number of uses, among them:
- Information for the compiler — Annotations can be used by the compiler to detect
errors or suppress warnings.
- Compile-time and deployment-time processing — Software tools can process
annotation information to generate code, XML files, and so forth.
- Runtime processing — Some annotations are available to be examined at runtime.

(12 marks)

HNDIT 2 Enterprise Architecture 2017


12

You might also like