0% found this document useful (0 votes)
44 views

Unit 1

The document discusses different database management system (DBMS) architecture styles including single-tier, two-tier, and three-tier architectures. It provides diagrams and examples of each. The three-tier architecture is described as the most popular and common, with presentation, application, and database layers separated on different tiers or servers. Benefits of the multi-tier architectures include added security, faster communication, and independent modification of components.

Uploaded by

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

Unit 1

The document discusses different database management system (DBMS) architecture styles including single-tier, two-tier, and three-tier architectures. It provides diagrams and examples of each. The three-tier architecture is described as the most popular and common, with presentation, application, and database layers separated on different tiers or servers. Benefits of the multi-tier architectures include added security, faster communication, and independent modification of components.

Uploaded by

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

Enterprise architecture styles: Single tier, 2-tier, 3-tier

A Database Architecture is a representation of DBMS design. It helps to design,


develop, implement, and maintain the database management system. A DBMS
architecture allows dividing the database system into individual components
that can be independently modified, changed, replaced, and altered. It also
helps to understand the components of a database.
A Database stores critical information and helps access data quickly and
securely. Therefore, selecting the correct Architecture of DBMS helps in easy and
efficient data management.

Types of DBMS Architecture


There are mainly three types of DBMS architecture:

 One Tier Architecture (Single Tier Architecture)


 Two Tier Architecture
 Three Tier Architecture

 1-Tier Architecture
 1 Tier Architecture in DBMS is the simplest architecture of Database in
which the client, server, and Database all reside on the same machine. A
simple one tier architecture example would be anytime you install a
Database in your system and access it to practice SQL queries. But such
architecture is rarely used in production.


 1 Tier Architecture Diagram
 2-Tier Architecture
 A 2 Tier Architecture in DBMS is a Database architecture where the
presentation layer runs on a client (PC, Mobile, Tablet, etc.), and data is
stored on a server called the second tier. Two tier architecture provides
added security to the DBMS as it is not exposed to the end-user directly. It
also provides direct and faster communication.

 2 Tier Architecture Diagram


 In the above 2 Tier client-server architecture of database management
system, we can see that one server is connected with clients 1, 2, and 3.
 Two Tier Architecture Example:
 A Contact Management System created using MS- Access.
3-Tier Architecture
A 3 Tier Architecture in DBMS is the most popular client server architecture in
DBMS in which the development and maintenance of functional processes,
logic, data access, data storage, and user interface is done independently as
separate modules. Three Tier architecture contains a presentation layer, an
application layer, and a database server.

3-Tier database Architecture design is an extension of the 2-tier client-server


architecture. A 3-tier architecture has the following layers:

1. Presentation layer (your PC, Tablet, Mobile, etc.)


2. Application layer (server)
3. Database Server

3 Tier Architecture Diagram


The Application layer resides between the user and the DBMS, which is
responsible for communicating the user’s request to the DBMS system and send
the response from the DBMS to the user. The application layer(business logic
layer) also processes functional logic, constraint, and rules before passing data
to the user or down to the DBMS.
MVC Architecture in Java
The Model-View-Controller (MVC) is a well-known design pattern in the web
development field. It is way to organize our code. It specifies that a program or
application shall consist of data model, presentation information and control
information. The MVC pattern needs all these components to be separated as
different objects.

In this section, we will discuss the MVC Architecture in Java, alongwith its advantages
and disadvantages and examples to understand the implementation of MVC in Java.

What is MVC architecture in Java?


The model designs based on the MVC architecture follow MVC design pattern. The
application logic is separated from the user interface while designing the software
using model designs.

The MVC pattern architecture consists of three layers:

o Model: It represents the business layer of application. It is an object to carry the data
that can also contain the logic to update controller if data is changed.
o View: It represents the presentation layer of application. It is used to visualize the
data that the model contains.
o Controller: It works on both the model and view. It is used to manage the flow of
application, i.e. data flow in the model object and to update the view whenever data
is changed.

In Java Programming, the Model contains the simple Java classes, the View used to
display the data and the Controller contains the servlets. Due to this separation the
user requests are processed as follows:
1. A client (browser) sends a request to the controller on the server side, for a page.
2. The controller then calls the model. It gathers the requested data.
3. Then the controller transfers the data retrieved to the view layer.
4. Now the result is sent back to the browser (client) by the view.

Advantages of MVC Architecture


The advantages of MVC architecture are as follows:

o MVC has the feature of scalability that in turn helps the growth of application.
o The components are easy to maintain because there is less dependency.
o A model can be reused by multiple views that provides reusability of code.
o The developers can work with the three layers (Model, View, and Controller)
simultaneously.
o Using MVC, the application becomes more understandable.
o Using MVC, each layer is maintained separately therefore we do not require to deal
with massive code.
o The extending and testing of application is easier.

A Web Service is can be defined by following ways:

o It is a client-server application or application component for communication.


o The method of communication between two devices over the network.
o It is a software system for the interoperable machine to machine
communication.
o It is a collection of standards or protocols for exchanging information between
two devices or application.

Let's understand it by the figure given below:

As you can see in the figure, Java, .net, and PHP applications can communicate with
other applications through web service over the network. For example, the Java
application can interact with Java, .Net, and PHP applications. So web service is a
language independent way of communication.

Types of Web Services


There are mainly two types of web services.

1. SOAP web services.


2. RESTful web services.
Web Service Features
XML-Based
Web services use XML at data description and data transportation layers. Using XML
exclude any networking, operating system, or platform binding. Web services-based
operation is extremely interoperable at their core level.

Loosely Coupled
A client of a web service is not fixed to the web service directly. The web service
interface can support innovation over time without negotiating the client's ability to
communicate with the service. A tightly coupled system means that the client and
server logic are closely tied to one another, indicating that if one interface changes,
then another must be updated. Accepting a loosely coupled architecture tends to
make software systems more manageable and allows more straightforward
integration between various systems.

Coarse-Grained
Object-oriented technologies such as Java expose their functions through individual
methods. A specific process is too fine an operation to provide any suitable capability
at a corporate level. Building a Java program from scratch needed the creation of
various fine-grained functions that are then collected into a coarse-grained role that
is consumed by either a client or another service.
Businesses and the interfaces that they prove should be coarse-grained. Web
services technology implement a natural method of defining coarse-grained services
that approach the right amount of business logic.

Ability to be Synchronous or Asynchronous


Synchronicity specifies the binding of the client to the execution of the function. In
synchronous invocations, the client blocks and delays in completing its service before
continuing. Asynchronous operations grant a client to invoke a task and then execute
other functions.

Asynchronous clients fetch their result at a later point in time, while synchronous
clients receive their effect when the service has completed. Asynchronous capability
is an essential method in enabling loosely coupled systems.

Supports Remote Procedure Calls (RPCs)


Web services allow consumers to invoke procedures, functions, and methods on
remote objects using an XML-based protocol. Remote systems expose input and
output framework that a web service must support.

Component development through Enterprise JavaBeans (EJBs) and .NET Components


has more become a part of architectures and enterprise deployments over a previous
couple of years. Both technologies are assigned and accessible through a variety of
RPC mechanisms.

Supports Document Exchange


One of the essential benefits of XML is its generic way of representing not only data
but also complex documents. These documents can be as simple as describing a
current address, or they can be as involved as defining an entire book or Request for
Quotation (RFQ). Web services support the transparent transfer of documents to
facilitate business integration.

Web Service Components


There are three major web service components.

1. SOAP
2. WSDL
3. UDDI
SOAP
SOAP is an acronym for Simple Object Access Protocol.

SOAP is a XML-based protocol for accessing web services.

SOAP is a W3C recommendation for communication between applications.

SOAP is XML based, so it is platform independent and language independent. In


other words, it can be used with Java, .Net or PHP language on any platform.

Advantages of Soap Web Services


WS Security: SOAP defines its own security known as WS Security.

Language and Platform independent: SOAP web services can be written in any
programming language and executed in any platform.

Disadvantages of Soap Web Services


Slow: SOAP uses XML format that must be parsed to be read. It defines many
standards that must be followed while developing the SOAP applications. So it is
slow and consumes more bandwidth and resource.

WSDL dependent: SOAP uses WSDL and doesn't have any other mechanism to
discover the service.

WSDL
WSDL is an acronym for Web Services Description Language.

WSDL is a xml document containing information about web services such as method
name, method parameter and how to access it.

WSDL is a part of UDDI. It acts as a interface between web service applications.

WSDL is pronounced as wiz-dull.

UDDI
UDDI is an acronym for Universal Description, Discovery and Integration.

UDDI is a XML based framework for describing, discovering and integrating web
services.

UDDI is a directory of web service interfaces described by WSDL, containing


information about web services.

RESTful Web Services


REST stands for REpresentational State Transfer.

REST is an architectural style not a protocol.

Advantages of RESTful Web Services


Fast: RESTful Web Services are fast because there is no strict specification like SOAP.
It consumes less bandwidth and resource.

Language and Platform independent: RESTful web services can be written in any
programming language and executed in any platform.

Can use SOAP: RESTful web services can use SOAP web services as the
implementation.

Permits different data format: RESTful web service permits different data format
such as Plain Text, HTML, XML and JSON.

SOAP vs REST Web Services


There are many differences between SOAP and REST web services. The important 10
differences between SOAP and REST are given below:

No. SOAP REST

1) SOAP is a protocol. REST is an architectural style.

2) SOAP stands for Simple Object REST stands for REpresentational State Transfer.
Access Protocol.

3) SOAP can't use REST because it is REST can use SOAP web services because it is a
a protocol. concept and can use any protocol like HTTP, SOAP.

4) SOAP uses services interfaces to REST uses URI to expose business logic.
expose the business logic.

5) JAX-WS is the java API for SOAP JAX-RS is the java API for RESTful web services.
web services.

6) SOAP defines standards to be REST does not define too much standards like SOAP.
strictly followed.

7) SOAP requires more REST requires less bandwidth and resource than
bandwidth and resource than SOAP.
REST.

8) SOAP defines its own security. RESTful web services inherits security measures from
the underlying transport.

9) SOAP permits XML data format REST permits different data format such as Plain text,
only. HTML, XML, JSON etc.

10) SOAP is less preferred than REST. REST more preferred than SOAP.

Component Class in Java

The Component class is the superclass of all components. A component


class can be linked with a page, components of web applications.
Component clearly shows that is the graphical representation of an Object.
Important methods of Component Class:
1. public void add(Component c): This method inserts a component
into a Container by taking a component as a parameter.
2. public void setSize(int width, int height): This method sets the
size of the component by taking height and width as parameters.
3. public void setLayout(LayoutManager lm): This method sets the
layout to set the components in a particular manner by taking
LayoutManager as a parameter.
4. public void setVisible(boolean status): This method sets the
visibility of a component to visible or not. If it sets to true then the
component will be visible in the output else if it sets to false or not
defined component won’t be visible in the output.

Types of Components in Component Class

1. Button
2. Label
3. Checkbox
4. Choice
5. List
All these components are present in java.awt package. We can import each
of the components individually i.e., import java.awt.Button, import
java.awt.Container etc.
Note: If we want to import all components at a time we can do that by
importing like import java.awt.*
The hierarchical structure of the above-listed components is below:
Hierarchical Structure of Components
Container
The Container is a component that will be used to extend other components
such as window, panel, Frame, Dialog, and Applet as shown in the above
diagram.
 Window: The Window is a Container that doesn’t include borders
and a menu bar. We must use another window, frames, and
dialogue box to create a Window. Creating an instance is the way
to create a Window Container.
 Panel: The Panel is also a Container that doesn’t include a title bar,
menu, or border. It is a container that holds components like
buttons, textfield, etc. Creating an instance is the way to create a
Panel Container and can add components.
 Frame: The Frame is a container used while creating an AWT
application. It can have components like title bar, menu bars,
borders and also buttons, scroll bar, etc.
 Dialog: The Dialog box is a container that will display the message
that we want to display on the screen.

SWING

Swing is a Java Foundation Classes [JFC] library and an extension of the


Abstract Window Toolkit [AWT]. Swing offers much-improved functionality
over AWT, new components, expanded components features, excellent
event handling with drag and drop support.

The hierarchy of java swing API is given below.


Difference between swing and awt

No. Java AWT Java Swing

1) AWT components are platform-dependent. Java swing components are platform-


independent.

2) AWT components are heavyweight. Swing components are lightweight.

3) AWT doesn't support pluggable look and feel. Swing supports pluggable look and
feel.

4) AWT provides less components than Swing. Swing provides more powerful
components such as tables, lists,
scrollpanes, colorchooser, tabbedpane
etc.

5) AWT doesn't follows MVC(Model View Controller) Swing follows MVC.


where model represents data, view represents
presentation and controller acts as an interface
between model and view.

omponents of Swing Classthe task’s percentage

Class Description

A Component is the Abstract base class for about the non menu
user-interface controls of SWING. Components are represents an
Component object with graphical representation

Container A Container is a component that can container SWING Components

A JComponent is a base class for all swing UI Components In order


to use a swing component that inherits from JComponent,
component must be in a containment hierarchy whose root is a top-
JComponent level Swing container

JLabel A JLabel is an object component for placing text in a container

JButton This class creates a labeled button

A JColorChooser provides a pane of controls designed to allow the


JColorChooser user to manipulate and select a color

A JCheckBox is a graphical(GUI) component that can be in either


JCheckBox an on-(true) or off-(false) state

The JRadioButton class is a graphical(GUI) component that can be


JRadioButton in either an on-(true) or off-(false) state. in the group

A JList component represents the user with the scrolling list of text
JList items

A JComboBox component is Presents the User with a show up


JComboBox Menu of choices

JTextField A JTextField object is a text component that will allow for the
Class Description

editing of a single line of text

A JPasswordField object it is a text component specialized for


JPasswordField password entry

A JTextArea object s a text component that allows for the editing of


JTextArea multiple lines of text

A ImageIcon control is an implementation of the Icon interface that


Imagelcon paints Icons from Images

A JScrollbar control represents a scroll bar component in order to


JScrollbar enable users to Select from range values

JOptionPane provides set of standard dialog boxes that prompt users


JOptionPane for a value or Something

A JFileChooser it Controls represents a dialog window from which


JFileChooser the user can select a file.

As the task progresses towards completion, the progress bar


JProgressBar displays the tasks percentage on its completion

A JSlider this class is lets the user graphically(GUI) select by using


JSlider a value by sliding a knob within a bounded interval.

A JSpinner this class is a single line input where the field that lets
the user select by using a number or an object value from an ordered
JSpinner sequence

Unit-2
NETWORKING

Java Socket Programming


Java Socket programming is used for communication between the applications
running on different JRE.

Java Socket programming can be connection-oriented or connection-less.

Socket and ServerSocket classes are used for connection-oriented socket


programming and DatagramSocket and DatagramPacket classes are used for
connection-less socket programming.

The client in socket programming must know two information:

1. IP Address of Server, and


2. Port number.

Here, we are going to make one-way client and server communication. In this
application, client sends a message to the server, server reads the message and
prints it. Here, two classes are being used: Socket and ServerSocket. The Socket class
is used to communicate client and server. Through this class, we can read and write
message. The ServerSocket class is used at server-side. The accept() method of
ServerSocket class blocks the console until the client is connected. After the
successful connection of client, it returns the instance of Socket at server-side.
Socket class
A socket is simply an endpoint for communications between the machines. The
Socket class can be used to create a socket.

Important methods

Method Description

1) public InputStream getInputStream() returns the InputStream attached with this socket.

2) public OutputStream getOutputStream() returns the OutputStream attached with this socket.

3) public synchronized void close() closes this socket


ServerSocket class
The ServerSocket class can be used to create a server socket. This object is used to
establish communication with the clients.

Important methods

Method Description

1) public Socket accept() returns the socket and establish a connection between server and clien

2) public synchronized void close() closes the server socket.

Example of Java Socket Programming


Creating Server:

To create the server application, we need to create the instance of ServerSocket class.
Here, we are using 6666 port number for the communication between the client and
server. You may also choose any other port number. The accept() method waits for
the client. If clients connects with the given port number, it returns an instance of
Socket.

1. ServerSocket ss=new ServerSocket(6666);


2. Socket s=ss.accept();//establishes connection and waits for the client

Creating Client:

To create the client application, we need to create the instance of Socket class. Here,
we need to pass the IP address or hostname of the Server and a port number. Here,
we are using "localhost" because our server is running on same system.

1. Socket s=new Socket("localhost",6666);


Java URL
The Java URL class represents an URL. URL is an acronym for Uniform Resource
Locator. It points to a resource on the World Wide Web. For example:

1. https://www.javatpoint.com/java-tutorial

A URL contains many information:

1. Protocol: In this case, http is the protocol.


2. Server name or IP Address: In this case, www.javatpoint.com is the server name.
3. Port Number: It is an optional attribute. If we write
http//ww.javatpoint.com:80/sonoojaiswal/ , 80 is the port number. If port number is
not mentioned in the URL, it returns -1.
4. File Name or directory name: In this case, index.jsp is the file name.

Constructors of Java URL class


URL(String spec)

Creates an instance of a URL from the String representation.

URL(String protocol, String host, int port, String file)

Creates an instance of a URL from the given protocol, host, port number, and file.

URL(String protocol, String host, int port, String file, URLStreamHandler


handler)

Creates an instance of a URL from the given protocol, host, port number, file, and
handler.

URL(String protocol, String host, String file)

Creates an instance of a URL from the given protocol name, host name, and file
name.
Commonly used methods of Java URL
class
The java.net.URL class provides many methods. The important methods of URL class are given
below.

Method Description

public String getProtocol() it returns the protocol of the URL.

public String getHost() it returns the host name of the URL.

public String getPort() it returns the Port Number of the URL.

public String getFile() it returns the file name of the URL.

public String getAuthority() it returns the authority of the URL.

public String toString() it returns the string representation of the URL.

public String getQuery() it returns the query string of the URL.

public String getDefaultPort() it returns the default port of the URL.

public URLConnection it returns the instance of URLConnection i.e. associated


openConnection() with this URL.

public boolean equals(Object obj) it compares the URL with the given object.

public Object getContent() it returns the content of the URL.

public String getRef() it returns the anchor or reference of the URL.

public URI toURI() it returns a URI of the URL.

Send email using Java Program


Sending Email is a basic requirement regardless of which platform you are working
on like JAVA, JavaEE, Python etc. Sending Email may be required to send error alerts
or confirmation of registration or signup. Java provides the facility to send emails by
writing java programs.
To send emails using Java, you need three things:

 JavaMail API
 Java Activation Framework (JAF)
 Your SMTP server details
You may download the latest version of both JavaMail API and JAF from the official
website of Java. After successfully downloading these two, extract them.
Add mail.jar , smtp.jar and activation.jar file in your classpath to be eligible to send
emails.
After adding these files, follow the below steps and write a java program to send
email:

 Create a new session object by calling getDefaultInstance() method and


passing properties as argument to get all of the important properties like
hostname of the SMTP server etc.
 Create a MimeMessage object by passing the session object created in
previous step.

 The final step is to send email using the javax.mail.Transport

JDBC
JDBC or Java Database Connectivity is a Java API to connect and execute
the query with the database. It is a specification from Sun microsystems that
provides a standard abstraction(API or Protocol) for java applications to
communicate with various databases. It provides the language with java
database connectivity standards. It is used to write programs required to
access databases. JDBC, along with the database driver, can access
databases and spreadsheets. The enterprise data stored in a relational
database(RDB) can be accessed with the help of JDBC APIs.
Components of JDBC
There are generally four main components of JDBC through which it can
interact with a database. They are as mentioned below:
1. JDBC API: It provides various methods and interfaces for easy
communication with the database. It provides two packages as follows,
which contain the java SE and Java EE platforms to exhibit WORA(write
once run anywhere) capabilities.
java.sql.*;
2. It also provides a standard to connect a database to a client application.
3. JDBC Driver manager: It loads a database-specific driver in an
application to establish a connection with a database. It is used to make a
database-specific call to the database to process the user request.
4. JDBC Test suite: It is used to test the operation(such as insertion,
deletion, updation) being performed by JDBC Drivers.
5. JDBC-ODBC Bridge Drivers: It connects database drivers to the
database. This bridge translates the JDBC method call to the ODBC function
call. It makes use of the sun.jdbc.odbc package which includes a native
library to access ODBC characteristics.

Architecture of JDBC

Architecture of JDBC

Description:
1. Application: It is a java applet or a servlet that communicates with
a data source.
2. The JDBC API: The JDBC API allows Java programs to execute
SQL statements and retrieve results. Some of the important classes
and interfaces defined in JDBC API are as follows:
3. DriverManager: It plays an important role in the JDBC architecture.
It uses some database-specific drivers to effectively connect
enterprise applications to databases.
4. JDBC drivers: To communicate with a data source through JDBC,
you need a JDBC driver that intelligently communicates with the
respective data source.
JDBC Drivers
JDBC drivers are client-side adapters (installed on the client machine, not on
the server) that convert requests from Java programs to a protocol that the
DBMS can understand. There are 4 types of JDBC drivers:
1. Type-1 driver or JDBC-ODBC bridge driver
2. Type-2 driver or Native-API driver
3. Type-3 driver or Network Protocol driver
4. Type-4 driver or Thin driver

Steps For Connectivity Between Java Program and Database


1. Import the Packages
2. Load the drivers using the forName() method
3. Register the drivers using DriverManager
4. Establish a connection using the Connection class object
5. Create a statement
6. Execute the query
7. Close the connections
Let us discuss these steps in brief before implementing by writing suitable
code to illustrate connectivity steps for JDBC/
Step 1: Import the Packages
Step 2: Loading the drivers
In order to begin with, you first need to load the driver or register it before
using it in the program. Registration is to be done once in your program. You
can register a driver in one of two ways mentioned below as follows:
2-A Class.forName()
Here we load the driver’s class file into memory at the runtime. No need of
using new or create objects. The following example uses Class.forName() to
load the Oracle driver as shown below as follows:
Class.forName(“oracle.jdbc.driver.OracleDriver”);
2-B DriverManager.registerDriver()
DriverManager is a Java inbuilt class with a static member register. Here we
call the constructor of the driver class at compile time. The following example
uses DriverManager.registerDriver()to register the Oracle driver as shown
below:
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver())
Step 3: Establish a connection using the Connection class object
After loading the driver, establish connections as shown below as follows:
Connection con = DriverManager.getConnection(url,user,password)
 user: Username from which your SQL command prompt can be
accessed.
 password: password from which the SQL command prompt can be
accessed.
 con: It is a reference to the Connection interface.
 Url: Uniform Resource Locator which is created as shown below:
String url = “ jdbc:oracle:thin:@localhost:1521:xe”

Step 4: Create a statement


Once a connection is established you can interact with the database. The
JDBCStatement, CallableStatement, and PreparedStatement interfaces
define the methods that enable you to send SQL commands and receive
data from your database.
Use of JDBC Statement is as follows:
Statement st = con.createStatement();

Step 5: Execute the query


Now comes the most important part i.e executing the query. The query here
is an SQL Query. Now we know we can have multiple types of
queries. Some of them are as follows:
 The query for updating/inserting a table in a database.
 The query for retrieving data.
The executeQuery() method of the Statement interface is used to execute
queries of retrieving values from the database. This method returns the
object of ResultSet that can be used to get all the records of a table.
The executeUpdate(sql query) method of the Statement interface is used to
execute queries of updating/inserting.

Step 6: Closing the connections


So finally we have sent the data to the specified location and now we are on
the verge of completing our task. By closing the connection, objects of
Statement and ResultSet will be closed automatically. The close() method of
the Connection interface is used to close the connection. It is shown below
as follows:
con.close();

You might also like