0% found this document useful (0 votes)
50 views13 pages

Java Assignment For Instructor David

This document contains a group assignment for a Java programming course at Wolaita Sodo University. The assignment asks students to explain the differences between Java AWT, Swing, and JavaFX classes, describe servlet architecture and handling HTTP requests, and discuss using JDBC with servlets in multitier applications. It then provides sample responses to the assignment questions covering the key features and differences between the GUI classes and an overview of servlets and request handling.

Uploaded by

Mintesnot Abebe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
50 views13 pages

Java Assignment For Instructor David

This document contains a group assignment for a Java programming course at Wolaita Sodo University. The assignment asks students to explain the differences between Java AWT, Swing, and JavaFX classes, describe servlet architecture and handling HTTP requests, and discuss using JDBC with servlets in multitier applications. It then provides sample responses to the assignment questions covering the key features and differences between the GUI classes and an overview of servlets and request handling.

Uploaded by

Mintesnot Abebe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

University of wolaita

Department
of computer
science

Course title: - java programming


Section -2
Instructor name-david
Group Assignment
Name Id
1. Mintesnot Abebe Geta----------------------WSU/CS /WE/128/12
2. Mebratu Markos----------------------------WSU/CS /WE/ /12
3. Konjit Fanta -------------------------------WSU/CS /WE/ /12
4. Mekibib Elias -------------------------------WSU/CS /WE/ /12
5. Merihun Ayele------------------------------WSU/CS /WE/ /12
6. Kidist Meskele------------------------------WSU/CS /WE/ /12
7. MEDHANIT LEMA ----------------------------- WSU/CS /WE/ /12

Reference book
Java web development 6th Edition
www.oracle.com
Title Page

CONTENTS

The Difference Between Java Awt, Swing And Javafx. ............................................................................. 3


The Awt Class .............................................................................................................................................. 3
The Main Different Of Java Awt Class From Swing And Javafx Classes. ................................................ 3
The Swing Class ........................................................................................................................................... 4
The Main Different Of Java Swing Class From Awt And Javafx Classes ................................................. 4
The Javafx Class ........................................................................................................................................... 5
The Main Different Of Javafx Swing Class From Awt And Swing Classes. ............................................. 5
Servlets With Its Architecture ...................................................................................................................... 6
The Power Of Servlets ................................................................................................................................. 8
Efficiency And Endurance ........................................................................................................................... 8
Elegance ........................................................................................................................................................ 8
Extensibility And Flexibility ......................................................................................................................... 9
Integration..................................................................................................................................................... 9
Handling Servlet Http Methods (Get And Post Requests) ......................................................................... 9
Get And Post ................................................................................................................................................ 9
Requests Redirection .................................................................................................................................. 10
Multitier Applications Using Jdbs From Servlet ....................................................................................... 11

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.)

The Difference Between Java Awt, Swing And Javafx.


Java language has the amazing features which allows java programmer to design any GUI elements by
writing codes into any compiler or terminals or by using screen builder java feature. Java foundation class (JFC)
are used to create java GUI application. By using the widely known Java compiler NetBeans IDE version 8.2 any
java programmers can design any GUI element or classes and act up on the code according to the program.

The Awt Class


 The first and the old well known JFC class is AWT or abstract windows toolkit. Java AWT is an API
(application program interface) used to develop graphical user interface or windows based application (not the
operating system windows).
 The Java AWT components are platform dependent which means components are classified according to the
operating system(OS) AWT is weight i.e. its components are using the resource of underlying operating
system.
The java.awt package provides classes for AWT API such as

 Text Field
 Label
 Textarea
 Radio Button
 Checkbox
 Choices
 List Etc…

The Main Different Of Java Awt Class From Swing And


Javafx Classes.
1. Java AWT class is platform dependent because AWT calls native platforms (operating system) for creating
API components like TextField CheckBox, Button, 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.

6. Control names are not the same for example:-

 AWT uses button b= new Button (“What’s Up”),while


 Swing uses JButton b= new JButton (“okay”)

7. AWT is not flexible when it is compared to swing class and javaFX.

8. You can add containers in container like- windows panel frame

 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

The Swing Class


 The second mostly used GUI class is called Swing was introduced in the release of java 2 swing
library it is an improved version of AWT class, swing provides an improved GUI application and
applet.

Swing also acts as widget toolkit for GUI

The java.swing package provides classes for swing API such as

 JButton,
 JLabel,
 JTextArea,
 JTable,
 Jlist etc…

The Main Different Of Java Swing Class From Awt And


Javafx Classes
1. Swing supersedes the AWT library and comes up with a look and feel that resembles most of the
platform.
2. The UI components that are created by swing are not only advance in terms of appearance and
feel, but they are also pluggable in nature. That means the underlying platform is not bounded with
a specific set of UI components. UI components like buttons, labels, and checkbox can be easily
created with Swing APIs. Thus,
3. Swing is more flexible in nature than AWT.

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.

The Javafx Class


 The third well known and use java foundation class (JFC) is javaFX, JavaFX act as a standard
GUI library, having extensive support for desktop computer and different web browsers on a
different operating system like Windows or Linux systems. Desktop applications can be created
efficiently using JavaFX, which act as a software platform. In the earlier edition of JavaFX, scripts
were being used to build JavaFX applications; these scripts were declarative and static in nature.
But with the advent of the JavaFX 2.0 version, it is implemented as a Java library, which means
applications now can be written using native Java code instead of scripts. With JavaFX, Java
developers can address all the issues which come along with modern UI design. A complex set of
controls are required in the modern UI, the responsiveness of UI is highly dependent upon
concurrency, but Java multi-threaded code requires a lot of boilerplate code addition.

The Main Different Of Javafx Swing Class From Awt And


Swing Classes.
1. JavaFX is used to build web software and desktop application.

2. JavaFX can run on multiple platform including

 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.

7. JavaFX has new up and coming feature reach UI components.

8. JavaFX is friendly with MVC (model view controller) platform while swing supports MVC across
components but lack consistency.

9. JavaFX have consistent look and feel in different platforms.

Servlets With Its Architecture


Let’s explore Servlets with its architecture.

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.

Java Servlet-based Web Server


Main Process
JVM
Request for Thread
Servlet1
Servlet1
Request for Thread

Servlet2 Servlet2
Thread
Request for
Servlet1

The servlet life cycle

Add-on servlet engines include the followings :

• 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.

• IBM’s WebSphere Application Server (formerly known as ServletExpress), a plug-in that is


being called an application server. It is designed to support the full Servlet API on several popular
web servers on several popular operating systems.

• 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.

The Power Of Servlets


New technology have portrayed servlets as an alternative to other dynamic web content
technologies.
What makes servlets a viable choice for web development? It is believe that servlets offer a
number of advantages over other approaches, including: portability, power, efficiency,
endurance, safety, elegance, integration, extensibility, and flexibility.

Servlets can harness the full power of the core Java APIs like:

 Networking And URL Access,


 Multithreading,
 Image manipulation
 Data compression
 Database connectivity
 Internationalization
 Remote method invocation (RMI)
 Corba connectivity
 And object serialization
 Among others.

Efficiency And Endurance


Servlet invocation is highly efficient. Once a servlet is loaded, it generally remains in the server’s
memory as a single object instance. Thereafter, the server invokes the servlet to handle a request
using a simple, lightweight method invocation. Unlike with CGI, there’s no process to spawn or
interpreter to invoke, so the servlet can begin handling the request almost immediately. Multiple,
concurrent requests are handled by separate threads, so servlets are highly scalable.
Servlets, in general, are naturally enduring objects. Because a servlet stays in the server’s memory
as a single object instance, it automatically maintains its state and can hold on to external resources,
such as database connections, that may otherwise take several seconds to establish.

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.

Handling Servlet Http Methods (Get And Post Requests)


An HTTP servlet can generate an HTML page, either when the servlet is accessed explicitly by
name, by following a hypertext link, or as the result of a form submission. An HTTP servlet can also
be embedded inside an HTML page, where it functions as a server-side include. Servlets can be
chained together to produce complex effects—one common use of this technique is for filtering
content. Finally, snippets of servlet code can be embedded directly in HTML pages using a new
technique called JavaServer Pages.

Get And Post


When a client connects to a server and makes an HTTP request, the request can be of several
different types, called methods. The most frequently used methods are GET and POST. Put simply,
the GET method is designed for getting information (a document, a chart, or the results from a
database query), while the POST method is designed for posting information (a credit card number,
some new chart data, or information that is to be stored in a database). To use a bulletin board
analogy, GET is for reading and POST is for tacking up new material.

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

Multitier Applications Using Jdbs From Servlet


The JDBC API is a Java API that can access any kind of tabular data, especially data stored in a relational
database.

JDBC helps you to write Java applications that manage these three programming activities:

Connect to a data source, like a database

Send queries and update statements to the database

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:

public void connectToAndQueryDatabase(String username, String password) {

Connection con = DriverManager.getConnection(

"jdbc:myDriver:myDatabase",

username,

password);

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");

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.

JDBC Product Components

JDBC includes four components:

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

You might also like