Final - MOST IMP QUESTION FOR GTU - 2020
Final - MOST IMP QUESTION FOR GTU - 2020
1) Initialization state(Born)
Applet enters the initialization state when it is first loaded,this is achieved by calling the init()
method of Applet class.
Initialization occurs only once in the applet’s life cycle.
To provide any of behaviour mentioned above,we must overrride init() method:
public void init()
{
............(Action)
............
}
2) Running state
Applet enters the running state when the system calls start() method of Applet class.
This occurs automatically after applet is initialized.
Unlike init() method,the start() method may be called more than once.
We may override the start() method to create a thread to control the applet.
public void start( )
{
............(Action)
............
}
[ALIGN= Alignment]
[VSPACE = Pixels]
[HSPACE = Pixles]
[<PARAM NAME=name1 VALUE= value1 >]
[<PARAM NAME=name2 VALUE= value2 >]
..............
</APPLET>
NO Attribute Meaning
CODE=AppletfileName.class Specifies the name of the applet class to be
1 (necessary) loaded.
CODEBASE= codebase_URL Specifies URL of the directory in which the
2 (Optional) applet resides.(must used in remote applet)
WIDTH = Pixels Specify width and height of the space on the
3 HEIGHT = Pixels(necessary) HTML page that will be reserved for applet.
Name = applet_instance_name A name for the other applet on the page may
4 (Optional) refer to this applet.
[ ALIGN= Alignment] Alignment of applet on page.
5
(Optional)
[ VSPACE = Pixels ] It specifies amount of vertical blank space the
6
(Optional) browser should leave surrounding the applet.
[ HSPACE = Pixels] It specifies amount of horizontal blank space the
7
(Optional) browser should leave surrounding the applet.
[ALT = Alternate text ] Non _java browser will display this text where
8
(Optional) the applet would normally go.
*/
public class ParamTest extends Applet
{
public void paint(Graphics g)
{
String s=getParameter("subject");
g.drawString("Name:="+s,50,50);
}
}
Output:
1) Component
Component class is derived from object class.
It is the super class for all AWT components class such as Label, TextComponent,
RadioButton, and CheckBox etc.
2) Container
Container class is derived from component class.
The Container is a component in AWT that can contain another component like buttons,
textfields, labels etc. The class that extends Container class is known as container such as
Frame, Dialog and Panel.
3) Windows
Windows class is derived from container class.
The window is the containers that have no borders and menu bars. You must use frame,
dialog or another window for creating a window.
4) Panel
Panel class is derived from container class.
The Panel is the container that doesn't contain title bar and menu bars. It can have other
components like button, textfield etc.
5) Frame
add(bt3);
add(bt4);
add(bt5);
add(bt6);
}}
Output:
2) BorderLayout Manager
It is the default layout for Frame and all windows.
In Border Layout components are added to the edges of container.
Border Layout provides five areas to place components like North, South, East, West,
and Center.
Constructor for BorderLayout:
BorderLayout ():-BorderLayout with empty direction.
Example: BorderLayout b1=new BorderLayout ();
Example:
import java.applet.*;
import java.awt.*;
/*<applet code=BorderDemo.class width=100 height=100>
</applet>*/
public class BorderDemo extends Applet
{
Button bt1=new Button("1");
Button bt2=new Button("2");
Button bt3=new Button("3");
Button bt4=new Button("4");
Button bt5=new Button("5");
add("South",bt2);
add("Center",bt3);
add("East",bt4);
add("West",bt5);
}}
Output:
The JDBC API supports both two-tier and three- tier architecture for database access.
Two-tier Architecture
Two-tier is based on client-server application.
Two-tier Architecture provides direct communication between Java applications and
database.
It requires a JDBC driver that can help to communicate with the particular database.
Query or request is sent by the user to the database and results are received back by the
user.
The database may be present on the same machine or any remote machine connected via a
network.
This approach is called client-server architecture or configuration.
Three-tier Architecture
Three –tier architecture are contain three Layers.
1) Client Layer(Presentation Layer)
2) Business Layer(Application Layer\Middle Layer)
3) Database Layer.
In this, there is no direct communication.
Requests are sent to the middle tier i.e. HTML browser sends a request to java application
which is then further sent to the database.
Database processes the request and sends the result back to the middle tier which then
communicates with the user.
Increases the performance and simplifies the application deployment.
In, type-1 driver a JDBC Bridge is used to access ODBC driver installed on each client
machine.
Type-1 driver translate all JDBC calls into ODBC calls and sent them to ODBC driver.
The ODBC driver depends on native library of the OS.
This driver is platform dependent.
Java 8 doesn’t support JDBC-ODBC driver.
Advantages:
Easy to use and install.
Can be easily connected to any database.
Disadvantages:
Not suitable for applet programming.
Install on each client machine.
Performance decrease because of JDBC call to ODBC call.
This driver is also known as Type-3 or pure java driver for database middleware.
This driver uses the 3-tier model.
It is fully written in java.
It converts JDBC call to directly or indirectly into Vendor specific database protocol.
These types of drivers are
very flexible.
Advantages:
The JDBC API provides the facility for accessing the relational database from the java
programming language.
The JDBC API provides the following interfaces and classes:
Driver Manager:
Driver Manager is very important part of JDBC architecture.
The main responsibility of JDBC driver manager is to load all the drivers found in the
system.
JDBC driver manager is a class in JDBC API.
The object of this class connects java application to a JDBC driver.
The JDBC driver also helps to select the most appropriate driver from the previous
loaded drivers when a new open database is connected.
Driver:
This interface handles the communication with the database server.
You will interact directly with driver object very rarely.
Using driver manager object we can manage object of this type.
It also implements the details associated with the working drivers object.
Connection:
This interface with all methods for contacting the database.
The connection object represents communication context
i.e.: all communication with the database is through connection object only.
Statement:
This interface is created to submit the sql statement to the database.
Same derived interface except parameters in addition to execute stored procedures or
functions.
ResultSet:
This interface stores data retrieve from database after executing some SQL statement.
It acts as an iterate to allow to move data to the next data.
SQLException:
This class handles errors that occur in database application.
17) Write Advantage and disadvantage of JDBC
Ans:
Advantages of JDBC:
Using JDBC, we can read any type of database if proper drivers are installed.
JDBC provides full access to metadata facility.
No content conversation is required in JDBC.
JDBC provides existing enterprise data.
We can create XML structure of data from database automatically.
JDBC supports query and store procedure.
JDBC require zero configurations for network computers.
JDBC is simplified enterprise development.
JDBC support modules.
Disadvantages of JDBC:
Correct drivers are needed for deployment of each type of database.
Can’t update or insert multiple tables with sequence.
When multiple connections are created or closed it affects the performance of database.
Creating a connection over and in this environment is too expensive.
18) Give difference between Servlet and Applet.
Ans:
Servlet Applet
A java Servlet executes on the Web A java Applet executes on the Web
Server in response to requests from a Browser.
Web Browser.
Servlet have no GUI. Applets are rich and powerful GUI
Servlet is server side technology. Applet is client side technology.
Servlet are more powerful than Java Applets are limited to certain
Applet. operations on the Browser.
Servlet can be used for server side data Applets can be used for client side
validation. data validation.
Syntax:
public void init (ServletConfig config) throws ServletException
{
//initialize code…
}
4) Call the Servlet Service ( ) method.
The container calls the service () method each time the request for Servlet is received.
Syntax:
Public void service (ServletRequest request, ServletResponce response) throws
ServletException, IOException
{
//code…
}
JSP Servlet
JSP is a file which consists of HTML tag Servlet is a java class.
and scripting code.
Files are saved using .jsp extension Files are saved using .java extension
It is server side scripting language which is Servlet is special program of JAVA that
used to develop dynamic web pages. is already compiled and used to create
dynamic web contents.
JSP run slower as compared to Servlet Servlet runs faster as compared to JSP
because we need to compile the code because Servlet is already compiled.
written in JSP to convert it in Servlet code.
Coding is easy in JSP as compared to Coding is difficult in Servlet as compared
Servlet. to JSP.
JSP are supported to HTTP protocol only. Servlet are supported to HTTP, FTP and
SMTP protocols.
22) List scripting Elements of JSP and Explain Expressions scripting element tag with an
example.
Ans:
The scripting elements provides the ability to insert java code inside the JSP
There are mainly three types of scripting elements:
1. Scriptlet tag
2. Expression tag
3. Declaration tag
1) Scriptlet tag
It is used to execute java source code in JSP.
A Scriptlet can contain any number of JAVA language statements, variable or method
declarations, or expressions that are valid in the page scripting language.
Syntax of Scriptlet: <% code fragment %>
You can write Scriptlet tag in XML as follows: <jsp:scriptlet> Code fragment </jsp:
Scriptlet>
Example: Write a program to print Hello world in JSP
<html>
<head>
<title>JSP Hello World</title> </head> <body>
<% out.println("Hello World<br>"); %> </body> </html>
Output: Hello World
2) Expression tag
The code placed within JSP expression tag is written to the output stream of the
response. So you need not write out.print () to write data.
It is mainly used to print the values of variable or method.
Syntax: <%= statement %>
Example of JSP expression tag
<html>
<body>
<%= "welcome to jsp" %>
</body>
</html>
Output: welcome to Jsp
3) Declaration tag
The JSP declaration tag is used to declare fields and methods.
We can declare static member, instance member, and method inside declaration tag.
The code placed in this tag must be end with semicolon (;).
Syntax: <%! Field or method declaration %>
Example of JSP expression tag
<html>
<body>
<%! Int data=50; %>
<%= "Value of the variable is:"+data %>
</body>
</html>
Output: Value of the variable is:50
Translation:
JSP container checks the JSP page code and converts it to generate the Servlet source
code.
After JSP page is translated into Servlet the entire request for that JSP page are served
by its related Servlet class.
Compilation of JSP Page
In this Java source code for the related Servlet is compiled by the JSP container. The
container converts source code into byte code.
Class loading:
In this Servlet class file is loaded by the class loader.
Instantiation:
Object of the Generated Servlet is created.
Initialization:
In this instantiated object is initialized. For this jspInit () method is invoked by the
container.
JspInit ( ) method declared in JSP page and it is implemented by JSP container.
This method called once in JSP life cycle to initialize it with config params configured
in deployment descriptor.
Request processing:
In this stage of JSP life cycle only those objects of a JSP equivalent Servlet that
initialized successfully are used by the web container to handle client request.
_jspService () method is invoked by the container for each client request by passing
request and response object.
Destroy:
If a Servlet container decides to destroy a Servlet instance of a JSP page Destroy ()
method is invoked by the container.
It clean up the environment .It is called only once in JSP life cycle.
Note: jspInit (), _jspService () and jspDestroy () are the life cycle methods of JSP.
24) Explain JSP declaration tag with example.
Ans: See in Question -22