Unit 1
Unit 1
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.
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.
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.
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.
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.
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.
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.
1. SOAP
2. WSDL
3. UDDI
SOAP
SOAP is an acronym for Simple Object Access Protocol.
Language and Platform independent: SOAP web services can be written in any
programming language and executed in any platform.
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.
UDDI
UDDI is an acronym for Universal Description, Discovery and Integration.
UDDI is a XML based framework for describing, discovering and integrating web
services.
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.
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.
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
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.
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
A JList component represents the user with the scrolling list of text
JList items
JTextField A JTextField object is a text component that will allow for the
Class Description
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
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.
Important methods
Method Description
1) public Socket accept() returns the socket and establish a connection between server and clien
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.
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. https://www.javatpoint.com/java-tutorial
Creates an instance of a URL from the given protocol, host, port number, and file.
Creates an instance of a URL from the given protocol, host, port number, file, and
handler.
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 boolean equals(Object obj) it compares the URL with the given object.
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:
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