Cs6501 - Internet Programming
Cs6501 - Internet Programming
Unit -1
1. Inheritance
2. Packages
3. Exception Handling
4. Multithreading
5. Applet (Smiley and Calculator Program)
Unit -2
1. Rich Internet Applications (8)
2. Collaborations tools (8)
3. Difference between websites and web server (8)
4. Difference between internet and intranet (8)
5. HTML and CSS Program (Given Program)
Unit - 3
1. DOM Model
2. Java Servlet Architecture
3. Servlet Life Cycle
4. Session Handling
5. Database connectivity (JDBC program example)
Unit -4
1. XML Schema
2. XML Parsers and Validation
3. XSL and XSLT Transformation
Unit -5
1. Ajax Client Server Architecture
2. Creating, Publishing, Testing and Describing a Web services (WSDL)
3. Database Driven web service from an application (SOAP).
Unit – I
Q1. Inheritance:
Inheritance can be defined as the process where one class acquires the
properties (methods and fields) of another. With the use of inheritance the
information is made manageable in a hierarchical order.
class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
Example
class Calculation {
int z;
public void addition(int x, int y) {
z = x + y;
System.out.println("The sum of the given numbers:"+z);
}
public void Subtraction(int x, int y) {
z = x - y;
System.out.println("The difference between the given numbers:"+z);
}
}
public class My_Calculation extends Calculation {
public void multiplication(int x, int y) {
z = x * y;
System.out.println("The product of the given numbers:"+z);
}
public static void main(String args[]) {
int a = 20, b = 10;
My_Calculation demo = new My_Calculation();
demo.addition(a, b);
demo.Subtraction(a, b);
demo.multiplication(a, b);
}
}
Output
java.io − classes for input , output functions are bundled in this package
Since the package creates a new namespace there won't be any name
conflicts with names in other packages. Using packages, it is easier to
provide access control and it is also easier to locate the related classes.
Example
Let us look at an example that creates a package called animals. It is a
good practice to use names of packages with lower case letters to avoid any
conflicts with the names of classes and interfaces.
interface Animal {
public void eat();
public void travel();
}
Now, let us implement the above interface in the same package animals −
package animals;
/* File name : MammalInt.java */
$ javac -d . Animal.java
$ javac -d . MammalInt.java
An exception can occur for many different reasons. Following are some
scenarios where an exception occurs.
A network connection has been lost in the middle of communications or the JVM
has run out of memory.
Exception Hierarchy
All exception classes are subtypes of the java.lang.Exception class. The
exception class is a subclass of the Throwable class. Other than the
exception class there is another subclass called Error which is derived from
the Throwable class.
Errors are abnormal conditions that happen in case of severe failures, these
are not handled by the Java programs. Errors are generated to indicate
errors generated by the runtime environment. Example: JVM is out of
memory. Normally, programs cannot recover from errors.
Catching Exceptions
A method catches an exception using a combination of
the try and catchkeywords. A try/catch block is placed around the code
that might generate an exception. Code within a try/catch block is referred
to as protected code, and the syntax for using try/catch looks like the
following −
Syntax
try {
// Protected code
}catch(ExceptionName e1) {
// Catch block
}
Syntax
try {
// Protected code
}catch(ExceptionType1 e1) {
// Catch block
}catch(ExceptionType2 e2) {
// Catch block
}catch(ExceptionType3 e3) {
// Catch block
}
The Throws/Throw Keywords
If a method does not handle a checked exception, the method must declare
it using the throws keyword. The throws keyword appears at the end of a
method's signature.
Using a finally block allows you to run any cleanup-type statements that
you want to execute, no matter what happens in the protected code.
A finally block appears at the end of the catch blocks and has the following
syntax −
Syntax
try {
// Protected code
}catch(ExceptionType1 e1) {
// Catch block
}catch(ExceptionType2 e2) {
// Catch block
}catch(ExceptionType3 e3) {
// Catch block
}finally {
// The finally block always executes.
}
class Division {
public static void main(String[] args) {
int a, b, result;
Scanner input = new Scanner(System.in);
System.out.println("Input two integers");
a = input.nextInt();
b = input.nextInt();
// try block
try {
result = a / b;
System.out.println("Result = " + result);
}
// catch block
catch (ArithmeticException e) {
System.out.println("Exception caught: Division by zero.");
}
}
}
Q4. Multithreading:
Java is a multi-threaded programming language which means we can
develop multi-threaded program using Java. A multi-threaded program
contains two or more parts that can run concurrently and each part can
handle a different task at the same time making optimal use of the
available resources specially when your computer has multiple CPUs.
Thread Priorities
Every Java thread has a priority that helps the operating system determine
the order in which threads are scheduled.
Threads with higher priority are more important to a program and should be
allocated processor time before lower-priority threads. However, thread
priorities cannot guarantee the order in which threads execute and are very
much platform dependent.
Step 1
As a first step, you need to implement a run() method provided by
a Runnableinterface. This method provides an entry point for the thread
and you will put your complete business logic inside this method. Following
is a simple syntax of the run() method −
Step 3
Once a Thread object is created, you can start it by calling start() method,
which executes a call to run( ) method. Following is a simple syntax of
start() method −
void start();
Example Program:
Here is an example that creates a new thread and starts running it −
Output
Creating Thread-1
Starting Thread-1
Creating Thread-2
Starting Thread-2
Running Thread-1
Thread: Thread-1, 4
Running Thread-2
Thread: Thread-2, 4
Thread: Thread-1, 3
Thread: Thread-2, 3
Thread: Thread-1, 2
Thread: Thread-2, 2
Thread: Thread-1, 1
Thread: Thread-2, 1
Thread Thread-1 exiting.
Thread Thread-2 exiting.
Q5. Applet
init − This method is intended for whatever initialization is needed for your
applet. It is called after the param tags inside the applet tag have been
processed.
start − This method is automatically called after the browser calls the init
method. It is also called whenever the user returns to the page containing the
applet after having gone off to other pages.
stop − This method is automatically called when the user moves off the page on
which the applet sits. It can, therefore, be called repeatedly in the same applet.
destroy − This method is only called when the browser shuts down normally.
Because applets are meant to live on an HTML page, you should not normally
leave resources behind after a user leaves the page that contains the applet.
paint − Invoked immediately after the start() method, and also any time the
applet needs to repaint itself in the browser. The paint() method is actually
inherited from the java.awt.
import java.applet.*;
g.setFont(f);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
eq.addActionListener(this);
cl.addActionListener(this);
paint();
//t1.addTextListener(this);
}
public void paint()
{
setBackground(Color.green);
}
t1.setText(String.valueOf(c));
}
if(s.equals("Clear"))
{
t1.setText("");
}
}
public void textValueChanged(TextEvent e)
{
}
}
Unit -2
HTML and CSS program:
HTML with inline CSS:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
styles.css
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
Output: