Java Assignment For Instructor David
Java Assignment For Instructor David
Department
of computer
science
Reference book
Java web development 6th Edition
www.oracle.com
Title Page
CONTENTS
JAVA-PROGRAMMING 2
Published by Mintesnot Abebe
Wolaita Sodo University
Course Title Java Programming
Group Assignment
1. Explain the difference between Java Awt, Swing and Java FX?
2. Explain servlet with its architecture?
3. Explain handling servlet HTTP methods (GET and POST requests.), Request redirection, (Multitier
applications using JDBS from servlet.)
Text Field
Label
Textarea
Radio Button
Checkbox
Choices
List Etc…
2. The big different between those class is that AWT is an older version of java GUI class.
3. The syntax we use to apply AWT is “import.java.awt.*;” while others classes uses other syntax
4. AWT communicate with a layer of software, peer classes.
5. AWT have heavyweight components while swing class have lightweight components.
Panel
Frame
9. A GUI written by AWT class have different look on different types of operating system like
windows, MAC OS or Linux.
10. AWT is not easily extendable by programmers because it have heavyweight components
JButton,
JLabel,
JTextArea,
JTable,
Jlist etc…
JAVA-PROGRAMMING 4
Published by Mintesnot Abebe
4. Swing provides a designer with a regular UI component but advanced components like
Tabbed
Panel,
Scroll Panes,
Tables,
Trees, Etc.
5. Swings have some added advantage over AWT, which makes Swing overtake AWT in developing
UI components.
6. UI components in Swing are developed entirely in Java and thus,
7. They are platform-independent, which is unlike AWT components. Swing’s framework is MVC, i.e.
Model-view-controller, which provides an abstraction between the graphics UI and the underlying
code structure. This abstraction helps the UI component writer in maintaining “separation of
concern” like architecture. Any developer can have access to all available Swing classes with their
complete documentation in the Java API guide. Swing’s classy aspect is its modular-based
architecture because this writer can come up with their own custom UI implementation of standard
UI components, resulting in overriding the default implementation using the Java inheritance
concept.
Web
Mobile
And desktop platforms
3. JavaFX has less components to legacy swing API, swing has more components than javaFX.
4. Rich GUI components can be made with advanced look and feel.
JAVA-PROGRAMMING 5
Published by Mintesnot Abebe
5. JavaFX uses script (syntax) and fast UI development with screen builder while AWT doesn’t have
API used to write UI components.
6. JavaFX has new rich toolkit while expected to grow in the future while Swing and AWT got no
new functionality for future even those there is no update in AWT classes.
8. JavaFX is friendly with MVC (model view controller) platform while swing supports MVC across
components but lack consistency.
Java Servlets are programs that run on a Web or Application server and act as a middle layer
between a requests coming from a Web browser or other HTTP client and databases or applications on
the HTTP server. By using Servlets, you can collect input from users through web page forms it allows
you to present records from a database or another source, and create web pages dynamically.
Java Servlets often serve the same purpose as programs implemented using the Common Gateway
Interface (CGI). But Servlets offer several advantages in comparison with the CGI but the performance
is significantly better.
Servlets execute within the address space of a Web server. It is not necessary to create a separate
process to handle each client request.
Servlets are platform-independent because they are written in Java so they can run on windows
platform or web platform or mobile platform.
Java security manager on the server enforces a set of restrictions to protect the resources on a
server machine so servlets are trusted.
The full functionality of the Java class libraries is available to a servlet. It can communicate with
applets, databases, or other software via the sockets and RMI mechanisms which includes Reading of
explicit data sent by the clients (browsers). This includes an HTML form on a Web page or it could also
come from an applet or a custom HTTP client program.
Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media
types and compression schemes the browser understands, and so forth.
Process the data and generate the results. This process may require talking to a database, executing
an RMI or CORBA call, invoking a Web service, or computing the response directly.
Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a
variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
Send the implicit HTTP response to the clients (browsers). This includes telling the browsers or
other clients what type of document is being returned (e.g., HTML), setting cookies and caching
parameters, and other such tasks.
JAVA-PROGRAMMING 6
Published by Mintesnot Abebe
Servlets Packages
Java Servlets are Java classes run by a web server that has an interpreter that supports the Java
Servlet specification.
Servlets can be created using the javax.servlet and javax.servlet.http packages, which are a standard
part of the Java's enterprise edition, an expanded version of the Java class library that supports large-
scale development projects
These classes implement the Java Servlet and JSP specifications. At the time of writing this tutorial,
the versions are Java Servlet 2.5 and JSP 2.1.
Java servlets have been created and compiled just like any other Java class.
Servlet2 Servlet2
Thread
Request for
Servlet1
• The Java-Apache project’s JServ module, a freely available servlet engine that adds servlet
support to the extremely popular Apache server.
• Live Software’s JRun, a freely available plug-in designed to support the full Servlet API on all
the popular web servers on all the popular operating systems. The latest version even features a
basic web server for development purposes.
• New Atlanta’s ServletExec, a plug-in designed to support the full Servlet API on several web
servers on several operating systems.
• Gefion Software’s WAICoolRunner, a freely available plug-in that supports most of the Servlet
API on Netscape’s FastTrack Server and Enterprise Server versions 3.x and later, written in Java
using Netscape’s WAI interface.
JAVA-PROGRAMMING 7
Published by Mintesnot Abebe
• Unicom’s Servlet CGI Development Kit, a freely available framework that supports servlets on
top of CGI. What it lacks in efficiency it makes up for in ubiquity.
Servlets can harness the full power of the core Java APIs like:
Elegance
The elegance of servlet code is striking. Servlet code is clean, object oriented, modular, and
amazingly simple. One reason for this simplicity is the Servlet API itself, which includes methods
and classes to handle many of the routine chores of servlet development. Even advanced
operations, like cookie handling and session tracking, are abstracted into convenient classes. A few
more advanced but still common tasks were left out of the API, and, in those places, we have tried
to step in and provide a set of helpful classes in the com.oreilly.servlet package.
JAVA-PROGRAMMING 8
Published by Mintesnot Abebe
Extensibility And Flexibility
The Servlet API is designed to be easily extensible. As it stands today, the API includes classes that
are optimized for HTTP servlets. But at a later date, it could be extended and optimized for another
type of servlets, either by Sun or by a third party. It is also possible that its support for HTTP
servlets could be further enhanced.
Integration
Servlets are tightly integrated with the server. This integration allows a servlet to cooperate with the
server in ways that a CGI program cannot. For example, a servlet can use the server to translate file
paths, perform logging, check authorization, perform MIME type mapping, and, in some cases,
even add users to the server’s user database. Server-specific extensions can do much of this, but the
process is usually much more complex and error-prone.
JAVA-PROGRAMMING 9
Published by Mintesnot Abebe
The GET method, although it’s designed for reading information, can include as part of the
request some of its own information that better describes what to get— such as an x, y scale for a
dynamically created chart. This information is passed as a sequence of characters appended to the
request URL in what’s called a query string. Placing the extra information in the URL in this way
allows the page to be bookmarked or emailed like any other. Because GET requests theoretically
shouldn’t need to send large amounts of information, some servers limit the length of URLs and query
strings to about 240 characters.
The POST method uses a different technique to send information to the server because in some
cases it may need to send megabytes of information. A POST request passes all its data, of unlimited
length, directly over the socket connection as part of its HTTP request body. The exchange is invisible
to the client. The URL doesn’t change at all. Consequently, POST requests cannot be bookmarked or
emailed or, in some cases, even reloaded. That’s by design—information sent to the server, such as
your credit card number, should be sent only once.
In practice, the use of GET and POST has strayed from the original intent. It’s common for long
parameterized requests for information to use POST instead of GET to work around problems with
overly-long URLs. It’s also common for simple forms that upload information to use GET because,
well—why not, it works! Generally, this isn’t much of a problem. Just remember that GET requests,
because they can be bookmarked so easily, should not be allowed to cause damage for which the
client could be held responsible. In other words, GET requests should not be used to place an order,
update a database, or take an explicit client action in any way.
Requests Redirection
The request uses the GET method to ask for the document named intro.html, using HTTP
Version 1.0. After sending the request, the client can send optional header information to tell the
server extra information about the request, such as what software the client is running and what
content types it understands. This information doesn’t directly pertain to what was requested, but it
could be used by the server in generating its response. Here are some sample request headers:
HTTP is a simple, stateless protocol. A client, such as a web browser, makes a request, the web
server responds, and the transaction is done. When the client sends a request, the first thing it
specifies is an HTTP command, called a method that tells the server the type of action it wants
JAVA-PROGRAMMING 10
Published by Mintesnot Abebe
performed. This first line of the request also specifies the address of a document (a URL) and the
version of the HTTP protocol it is using. For example:
GET /intro.html HTTP/1.0
JDBC helps you to write Java applications that manage these three programming activities:
Retrieve and process the results received from the database in answer to your query
The following simple code fragment gives a simple example of these three steps:
"jdbc:myDriver:myDatabase",
username,
password);
while (rs.next()) {
int x = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c");
This short code fragment instantiates a DriverManager object to connect to a database driver and log into
the database, instantiates a Statement object that carries your SQL language query to the database;
JAVA-PROGRAMMING 11
Published by Mintesnot Abebe
instantiates a ResultSet object that retrieves the results of your query, and executes a simple while loop,
which retrieves and displays those results. It's that simple.
The JDBC API — The JDBC™ API provides programmatic access to relational data from the Java™
programming language. Using the JDBC API, applications can execute SQL statements, retrieve results,
and propagate changes back to an underlying data source. The JDBC API can also interact with multiple
data sources in a distributed, heterogeneous environment.
The JDBC API is part of the Java platform, which includes the Java™ Standard Edition (Java™ SE ) and
the Java™ Enterprise Edition (Java™ EE). The JDBC 4.0 API is divided into two packages: java.sql and
javax.sql. Both packages are included in the Java SE and Java EE platforms.
JDBC Driver Manager — The JDBC DriverManager class defines objects which can connect Java
applications to a JDBC driver. DriverManager has traditionally been the backbone of the JDBC
architecture. It is quite small and simple.
The Standard Extension packages javax.naming and javax.sql let you use a DataSource object registered
with a Java Naming and Directory Interface™ (JNDI) naming service to establish a connection with a
data source. You can use either connecting mechanism, but using a DataSource object is recommended
whenever possible.
JDBC Test Suite — The JDBC driver test suite helps you to determine that JDBC drivers will run your
program. These tests are not comprehensive or exhaustive, but they do exercise many of the important
features in the JDBC API.
JDBC-ODBC Bridge — The Java Software bridge provides JDBC access via ODBC drivers. Note that
you need to load ODBC binary code onto each client machine that uses this driver. As a result, the
ODBC driver is most appropriate on a corporate network where client installations are not a major
problem, or for application server code written in Java in a three-tier architecture.
This Trail uses the first two of these four JDBC components to connect to a database and then build a
java program that uses SQL commands to communicate with a test relational database. The last two
JAVA-PROGRAMMING 12
Published by Mintesnot Abebe
components are used in specialized environments to test web applications, or to communicate with
ODBC-aware DBMSs.
JAVA-PROGRAMMING 13
Published by Mintesnot Abebe