Web Technology UNIT-1
Web Technology UNIT-1
UNIT-4
Introduction: Introduction and Web Development Strategies, History of Web and Internet,
Protocols Governing Web, Writing Web Projects, Connecting to Internet, Introduction to
Internet services and tools, Introduction to client-server computing. Core Java:
Introduction, Operator, Data type, Variable, Arrays, Methods & Classes, Inheritance,
Package and Interface, Exception Handling, Multithread programming, I/O, Java Applet,
String handling, Event handling, Introduction to AWT, AWT controls, Layout managers.
Introduction and Web Development Strategies
History of WWW
2. This protocol operates at the application layer. 2. This protocol operates at the transport layer.
3. The data which is transferred in HTTP is plain 3. The data which is transferred in HTTPS is
text. encrypted, i.e., ciphertext.
4. By default, this protocol operates on port 4. By default, this protocol operates on port
number 80. number 443.
5. The URL (Uniform Resource Locator) of 5. The URL (Uniform Resource Locator) of
HTTP start with http:// HTTPS start with https://
6. This protocol does not need any certificate. 6. But, this protocol requires an SSL (Secure
Socket Layer) certificate.
8. The speed of HTTP is fast as compared to 8. The speed of HTTPS is slow as compared to
HTTPS. HTTP.
A. Corporate Website:
i. In this, there is certain no. of persons, who develop their website for a particular
organization.
ii. The corporate website are formed when group of people have common interest
and objective.
iii. The purpose of this website is to convey the information of organization to all over
the world.
B. Individual website: It is just like profile management system. In this type of website an
individual wants to develop website for h-projection, career growth etc.
Web Applications:
a. Simple office software (word processors, online spreadsheets, and presentation tools).
b. More advanced applications such as project management, computer-aided
design, video editing and point-of-sale.
Writing web Projects and Target Users:
A. Write a project mission statement: Write the specific mission statement that you
want to do.
B. Identify Objectives:
i. Specific
ii. Measurable
iii. Attainable
iv. Realistic
v. Time limited
C. Identify your target users: The matter of a website will be determined by the users
whom you want to visit the site. This is totally depend upon
i. Market research
ii. Focus group
iii. Understanding intranet audiences
D. Determine the scope: By supporting documents and client’s approval.
E. Budget:
i. Assumption for budgets.
ii. Budget categories.
iii. Determine hidden costs and tools.
F. Planning issues:
i. Discuss client’s existing information system.
ii. Project team and developing infrastructure.
iii. Where the website will place.
ARPANET:
In 1969, a project was funded by the Advanced Research Project Agency (ARPA), an
arm of the U.S. Department of Defence. ARPA established a packet-switching network of
computers linked by point-to-point leased lines called Advanced Research Project
agency Network (ARPANET) that provided a basis for early research into networking.
The conventions developed by ARPA is specify how individual computers could
communicate across that network became TCP/IP.
As networking possibilities grew to include other types of links and devices, ARPA
adapted TCP/IP to the demands of the new technology. As involvement in TCP/IP grew,
the scope of ARPANET expanded until it became the backbone of an internet- work
today referred to as the internet.
ISP:
The Internet Service Provider (ISP) gives you the telephone access and software you
need to connect to the internet along with some technical help.
Many ISPs also include an electronic mail account, host customers web pages and
offer services a company that do business on the Internet.
There are aprox. 200 ISPs in India like VSNL, MTNL, ERNET (Education and
Research Community Network) etc.
Introduction to Java:
Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike
Sheridan at Sun Microsystems, Inc. in 1991. It took 18 months to develop the first working
version. This language was initially called “Oak” but was renamed “Java” in 1995.
Java Applets and Applications
Java can be used to create two types of programs: applications and applets. An application is a
program that runs on your computer, under the operating system of that computer. That is, an
application created by Java is more or less like one created using C or C++. When used to create
applications, Java is not much different from any other computer language.
An applet is an application designed to be transmitted over the Internet and executed by a Java-
compatible Web browser. An applet is actually a tiny Java program, dynamically downloaded
across the network, just like an image, sound file, or video clip. The important difference is that
an applet is an intelligent program, not just an animation or media file. In other words, an applet
is a program that can react to user input and dynamically change—not just run the same
animation or sound over and over.
JDK (Java Development Kit).The Java Development Kit (JDK) is a software development
environment which is used to develop Java applications and applets. It physically exists. It
contains JRE + development tools. The JDK contains a private Java Virtual Machine (JVM) and
a few other resources such as an interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the development of a Java Application.
Java Virtual Machine (JVM) is a engine that provides runtime environment to drive the Java
Code or applications. It converts Java bytecode into machines language. JVM is a part of Java
Runtime Environment (JRE). In other programming languages, the compiler produces machine
code for a particular system. However, Java compiler produces code for a Virtual Machine
known as Java Virtual Machine.
Here is how JVM works
First, Java code is compiled into bytecode. This bytecode gets interpreted on different machines
Between host system and Java source, Bytecode is an intermediary language.
JVM in Java is responsible for allocating memory space.
JVM Architecture
Let's understand the internal architecture of JVM. It contains classloader, memory area,
execution engine etc.
1) Classloader
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java
program, it is loaded first by the classloader. There are three built-in classloaders in Java.
1. Bootstrap ClassLoader: This is the first classloader which is the super class of
Extension classloader. It loads the rt.jar file which contains all class files of Java
Standard Edition like java.lang package classes, java.net package classes, java.util
package classes, java.io package classes, java.sql package classes etc.
2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader
of System classloader. It loades the jar files located
inside $JAVA_HOME/jre/lib/ext directory.
3. System/Application ClassLoader: This is the child classloader of Extension classloader.
It loads the classfiles from classpath. By default, classpath is set to current directory. You
can change the classpath using "-cp" or "-classpath" switch. It is also known as
Application classloader.
2) Class(Method) Area
Class(Method) Area stores per-class structures such as the runtime constant pool, field and
method data, the code for methods.
3) Heap
It is the runtime data area in which objects are allocated.
4) Stack
Java Stack stores frames. It holds local variables and partial results, and plays a part in method
invocation and return.
Each thread has a private JVM stack, created at the same time as thread.
A new frame is created each time a method is invoked. A frame is destroyed when its method
invocation completes.
5) Program Counter Register
PC (program counter) register contains the address of the Java virtual machine instruction
currently being executed.
6) Native Method Stack
It contains all the native methods used in the application.
7) Execution Engine
It contains:
1. A virtual processor
2. Interpreter: Read bytecode stream then execute the instructions.
3. Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts
of the byte code that have similar functionality at the same time, and hence reduces the
amount of time needed for compilation. Here, the term "compiler" refers to a translator
from the instruction set of a Java virtual machine (JVM) to the instruction set of a
specific CPU.
8) Java Native Interface
Java Native Interface (JNI) is a framework which provides an interface to communicate with
another application written in another language like C, C++, Assembly etc. Java uses JNI
framework to send output to the Console or interact with OS libraries.
Software Code Compilation & Execution process
In order to write and execute a software program, you need the following
1) Editor – To type your program into, a notepad could be used for this
2) Compiler – To convert your high language program into native machine code
3) Linker – To combine different program files reference in your main program together.
4) Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive,
CD into RAM for execution. The loading is automatically done when you execute your code.
5) Execution – Actual execution of the code which is handled by your OS & processor.
With this background, refer the following video & learn the JVM internal working and
architecture of JVM (Java Virtual Machine).
Bytecode
Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time
system, which is called the Java Virtual Machine (JVM). That is, in its standard form, the JVM is
an interpreter for bytecode.
JVM: Translating a Java program into bytecode helps makes it much easier to run a program in a
wide variety of environments. The reason is straightforward: only the JVM needs to be
implemented for each platform. Once the run-time package exists for a given system, any Java
program can run on it.
1 + ( Addition )
Adds values on either side of the operator
Example: A + B will give 30
2 - ( Subtraction )
Subtracts right hand operand from left hand operand
Example: A - B will give -10
3 * ( Multiplication )
Multiplies values on either side of the operator
Example: A * B will give 200
4 / (Division)
Divides left hand operand by right hand operand
Example: B / A will give 2
5 % (Modulus)
Divides left hand operand by right hand operand and returns remainder
Example: B % A will give 0
6 ++ (Increment)
Increases the value of operand by 1
Example: B++ gives 21
7 -- ( Decrement )
Decreases the value of operand by 1
Example: B-- gives 19
1 == (equal to)
Checks if the values of two operands are equal or not, if yes then condition
becomes true.
Example: (A == B) is not true.
2 | (bitwise or)
Binary OR Operator copies a bit if it exists in either operand.
Example: (A | B) will give 61 which is 0011 1101
3 ^ (bitwise XOR)
Binary XOR Operator copies the bit if it is set in one operand but not both.
Example: (A ^ B) will give 49 which is 0011 0001
4 ~ (bitwise compliment)
Binary Ones Complement Operator is unary and has the effect of 'flipping' bits.
Example: (~A ) will give -61 which is 1100 0011 in 2's complement form due to a
signed binary number.
5 << (left shift)
Binary Left Shift Operator. The left operands value is moved left by the number of
bits specified by the right operand
Example: A << 2 will give 240 which is 1111 0000
2 || (logical or)
Called Logical OR Operator. If any of the two operands are non-zero, then the
condition becomes true.
Example (A || B) is true.
3 ! (logical not)
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a
condition is true then Logical NOT operator will make false.
Example !(A && B) is true.
1 =
Simple assignment operator, Assigns values from right side operands to left side
operand.
Example: C = A + B will assign value of A + B into C
2 +=
Add AND assignment operator, It adds right operand to the left operand and assign
the result to left operand.
Example: C += A is equivalent to C = C + A
3 -=
Subtract AND assignment operator, It subtracts right operand from the left operand
and assign the result to left operand.
Example:C -= A is equivalent to C = C - A
4 *=
Multiply AND assignment operator, It multiplies right operand with the left operand
and assign the result to left operand.
Example: C *= A is equivalent to C = C * A
5 /=
Divide AND assignment operator, It divides left operand with the right operand and
assign the result to left operand
ExampleC /= A is equivalent to C = C / A
6 %=
Modulus AND assignment operator, It takes modulus using two operands and
assign the result to left operand.
Example: C %= A is equivalent to C = C % A
7 <<=
Left shift AND assignment operator.
ExampleC <<= 2 is same as C = C << 2
8 >>=
Right shift AND assignment operator
Example C >>= 2 is same as C = C >> 2
9 &=
Bitwise AND assignment operator.
Example: C &= 2 is same as C = C & 2
10 ^=
bitwise exclusive OR and assignment operator.
Example: C ^= 2 is same as C = C ^ 2
11 |=
bitwise inclusive OR and assignment operator.
Example: C |= 2 is same as C = C | 2
Conditional Operator ( ? : )
Conditional operator is also known as the ternary operator. This operator consists of three
operands and is used to evaluate Boolean expressions. The goal of the operator is to decide which
value should be assigned to the variable. The operator is written as:
variable x = (expression) ? value if true : value if false
Data Types
Java defines eight simple (or elemental) types of data: byte, short, int, long,
char, float, double, and boolean. These can be put in four groups:
1. Integers This group includes byte, short, int, and long, which are for
whole valued signed numbers.
2. Floating-point numbers This group includes float and double, which
represent numbers with fractional precision.
3. Characters This group includes char, which represents symbols in a
character set, like letters and numbers.
4. Boolean This group includes boolean, which is a special type for
representing true/false values.
byte:
Byte data type is an 8-bit signed two's complement integer.
Minimum value is -128 (-2^7)
Maximum value is 127 (inclusive)(2^7 -1)
Default value is 0
short:
Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 (-2^15)
Maximum value is 32,767 (inclusive) (2^15 -1)
Default value is 0
int:
Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648.(-2^31)
Maximum value is 2,147,483,647(inclusive).(2^31 -1)
Default value is 0
long:
Long data type is a 64-bit signed two's complement integer.
Minimum value is -9,223,372,036,854,775,808.(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)
This type is used when a wider range than int is needed.
Default value is 0L.
float:
Float data type is a single-precision 32-bit IEEE 754 floating point.
Float is mainly used to save memory in large arrays of floating point numbers.
Default value is 0.0f.
Float data type is never used for precise values such as currency.
Example: float f1 = 234.5f
double:
double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values, generally the
default choice.
Double data type should never be used for precise values such as currency.
Default value is 0.0d.
Example: double d1 = 123.4
boolean:
boolean data type represents one bit of information.
There are only two possible values: true and false.
This data type is used for simple flags that track true/false conditions.
Default value is false.
Example: boolean one = true
char:
char data type is a single 16-bit Unicode character.
Minimum value is '\u0000' (or 0).
Maximum value is '\uffff' (or 65,535 inclusive).
Char data type is used to store any character.
Variables
The variable is the basic unit of storage in a Java program. A variable is defined by
the combination of an identifier, a type, and an optional initializer. In addition, all
variables have a scope, which defines their visibility, and a lifetime.
Declaring a Variable
In Java, all variables must be declared before they can be used. The basic form of
a variable declaration is shown here:
type identifier [ = value][, identifier [= value] ...] ;
Arrays
An array is a group of like-typed variables that are referred to by a common name.
Arrays of any type can be created and may have one or more dimensions. A specific
element in an array is accessed by its index. Arrays offer a convenient means of grouping
related information.
One-Dimensional Arrays
A one-dimensional array is, essentially, a list of like-typed variables. To create an array,
you first must create an array variable of the desired type. The general form of a one
dimensional array declaration is
type var-name[ ];
Here, type declares the base type of the array. The base type determines the data type of
each element that comprises the array. How to allocate memory for arrays? The general
form of new as it applies to one-dimensional arrays appears as follows:
array-var = new type[size];
Here, type specifies the type of data being allocated, size specifies the number of
elements in the array, and array-var is the array variable that is linked to the array.
Multidimensional Arrays
In Java, multidimensional arrays are actually arrays of arrays. declare a multidimensional
array variable, specify each additional index using another set of square brackets. For
example, the following declares a two-dimensional array variable called twoD.
int twoD[][] = new int[4][5];
This allocates a 4 by 5 array and assigns it to twoD
// Demonstrate a two-dimensional array.
class TwoDArray {
public static void main(String args[])
{
int twoD[][]= new int[4][5];
int i, j, k = 0;
for(i=0; i<4; i++)
for(j=0; j<5; j++) {
twoD[i][j] = k;
k++;}
for(i=0; i<4; i++) {
for(j=0; j<5; j++)
System.out.print(twoD[i][j] + " ");
System.out.println();}}}
This program generates the following output:
01234
56789
10 11 12 13 14
15 16 17 18 19
Classes
It is the logical construct upon which the entire Java language is built because it
defines the shape and nature of an object. As such, the class forms the basis for
object-oriented programming in Java. Any concept you wish to implement in a
Java program must be encapsulated within a class.
Perhaps the most important thing to understand about a class is that it defines a
new data type. Once defined, this new type can be used to create objects of that
type.
Thus, a class is a template for an object, and an object is an instance of a class.
Because an object is an instance of a class, you will often see the two words object
and instance used interchangeably. A class is declared by use of the class keyword.
The general form of a class definition is shown here
class classname {
type instance-variable1;
type instance-variable2;
// ...
type instance-variableN;
type methodname1(parameter-list) {
// body of method
}
type methodname2(parameter-list) {
// body of method
}
// ...
type methodnameN(parameter-list) {
// body of method
}
}
The data, or variables, defined within a class are called instance variables. The
code is contained within methods. Collectively, the methods and variables defined
within a class are called members of the class.
Methods
This is the general form of a method:
type name(parameter-list)
{
// body of method
}
Here, type specifies the type of data returned by the method. This can be any valid
type, including class types that you create. If the method does not return a value, its
return type must be void. The name of the method is specified by name. This can
be any legal identifier other than those already used by other items within the
current scope. The parameter-list is a sequence of type and identifier pairs
separated by commas. Parameters are essentially variables that receive the value of
the arguments passed to the method when it is called. If the method has no
parameters, then the parameter list will be empty.
Method Overloading
If a class has multiple methods by same name but different parameters, it is known
as Method Overloading.
If we have to perform only one operation, having same name of the methods
increases the readability of the program.
Suppose you have to perform addition of the given numbers but there can be any
number of arguments, if you write the method such as a(int,int) for two parameters,
and b(int,int,int) for three parameters then it may be difficult for you as well as
other programmers to understand the behaviour of the method because its name
differs. So, we perform method overloading to figure out the program quickly
Advantage of method overloading
Method overloading increases the readability of the program.
We have created two overloaded methods, first sum method performs addition of
two numbers and second sum method performs addition of three numbers.
class Calculation{
void sum(int a,int b)
{
System.out.println(a+b);
}
void sum(int a,int b,int c){
System.out.println(a+b+c);
}
public static void main(String args[]) {
Calculation obj=new Calculation();
obj.sum(10,10,10);
obj.sum(20,20);
}
}
Output: 30
40
Method Overriding
If subclass (child class) has the same method as declared in the parent class, it is
known as method overriding in java.
In other words, If subclass provides the specific implementation of the method that
has been provided by one of its parent class, it is known as method overriding.
Usage of Java Method Overriding
Method overriding is used to provide specific implementation of a method
that is already provided by its super class.
Method overriding is used for runtime polymorphism
Rules for Java Method Overriding
1. method must have same name as in the parent class
2. method must have same parameter as in the parent class.
3. must be IS-A relationship (inheritance).
Example
class Vehicle{
void run()
{
System.out.println("Vehicle is running");
}
}
class Bike2 extends Vehicle{
void run(){
System.out.println("Bike is running safely");
}
public static void main(String args[]){
Bike2 obj = new Bike2();
obj.run();
}
Output: Bike is running safely
There are many differences between method overloading and method overriding in
java. A list of differences between method overloading and method overriding are
given below:
Inheritance in Java
Inheritance in java is a mechanism in which one object acquires all the properties
and behaviors of parent object.
The idea behind inheritance in java is that you can create new classes that are built
upon existing classes. When you inherit from an existing class, you can reuse
methods and fields of parent class, and you can add new methods and fields also.
Inheritance represents the IS-A relationship, also known as parent-child
relationship.
Why use inheritance in java
Method Overriding (so runtime polymorphism can be achieved).
Code Reusability.
Code Sharing
Syntax of Java Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}
The extends keyword indicates that you are making a new class that derives from
an existing class.
In the terminology of Java, a class that is inherited is called a super class. The new
class is called a subclass.
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
Output:
Programmer salary is: 40000.0
Bonus of programmer is: 10000
In the above example, Programmer object can access the field of own class as well
as of Employee class i.e. code reusability.