WebTechnology.Unit.I.Notes
WebTechnology.Unit.I.Notes
Unit 1
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, String
handling
Unit II
Introduction to Web
● The Web is the common name for the World Wide Web, a subset of the Internet consisting
of the pages that can be accessed by a Web browser.
● Many people assume that the Web is the same as the Internet, and use these terms
interchangeably.
● However, the term Internet actually refers to the global network of servers that makes the
information sharing that happens over the Web possible.
● So, although the Web does make up a large portion of the Internet, but they are not one and
same.
What is World Wide Web (WWW)?
• It is a collection of Millions of files stored on thousands of computers (Web Servers) all over
the world.
• These files may be HTML Documents, Text Documents, pictures, videos, sounds, programs
etc.
• Created by Tim Berners Lee in 1991.
● There is no central governing body of the Internet. Instead, each constituent network setting
follows its own lead and enforces its own policies.
● But even though no sole entity runs the Internet, there are still a few smaller institutions
that have a bit of control.
• HTTP is a pull protocol, the user pulls information from a remote site.
• Protocol consists of GET and POST commands to transfer data.
• HTTP uses cached files to speed up transfers
• HTTP Uses LAN accessible cache that is Proxy Server.
• Proxy allows for reduced load on the internet connection
HTTPS (Hyper Text Transfer Protocol Secure)
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP).
It is used for secure communication over a computer network, and is widely used on the Internet. In
HTTPS, the communication protocol is encrypted using Transport Layer Security (TLS) or, formerly,
Secure Sockets Layer (SSL). The protocol is therefore also referred to as HTTP over TLS or HTTP over
SSL.
Information Gathering
Planning
Design
Development
Testing
Delivery or Hosting
Maintenance Phase
Client–server model is a distributed application structure that partitions tasks or workloads between
the providers of a resource or service, called servers, and service requesters, called clients. Often
clients and servers communicate over a computer network on separate hardware, but both client and
server may reside in the same system. A server host runs one or more server programs, which share
their resources with clients. A client usually does not share any of its resources, but it requests content
or service from a server. Clients, therefore, initiate communication sessions with servers, which await
incoming requests. Examples of computer applications that use the client–server model are email,
network printing, and the World Wide Web.
Introduction to Java
Java is a high level class based object oriented programming language
It is a general purpose programming language intended to let application developers Write
Once Run Anywhere (WORA)
Java was originally developed by James Gosling at Sun Microsystems and released in 1995 as
a core component of Sun Microsystems' Java platform Sun Microsystems was acquired by
Oracle in 2010
History of Java
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in
June 1991
The language was initially called Oak after an oak tree that stood outside Gosling's office
Later the project went by the name Green and was finally renamed Java from Java coffee, a
type of coffee from Indonesia
Sun Microsystems released the first public implementation as Java 1 0 in 1996
The latest version is Java 17 released in September 2021
Resource URL:
https://java.sun.com/
Java SE 17 Download
IntelliJ IDEA Community Edition Download
A user defined data type used to classify different entities like Student, Employee, Book,
Department
A class contains a set of data members and the methods applicable on an entity
Classes can be of two types
o Library Classes
o User Defined Classes
The classes which are provided with Java Development Kit for Rapid Application Development
(RAD)
o String class
o Character class
o Math class
o System class
String class provides the methods applicable on a string like length(), toUpperCase (),
toLowerCase ()
Math class provides the methods required for mathematical operations like pow(), sqrt (),
log()
System class provides reference variables and the methods to interact with the computer
system
The System class provides three built in reference variables to refer the input and output
devices in a computer system
o in refers to standard input (keyboard)
o out refers to standard output (monitor)
o err refers to standard error (monitor)
These reference variables can be used to call the methods provided in their classes
InputStream and OutputStream
print()
o To print some output to the monitor
println()
o To print some output to the monitor with line break
printf()
o To print formatted output to the monitor using format specifiers
What is entry point?
Special method inside a class from where the runtime environment starts execution is called
as entry point
Entry point can by any of three choices
o public static void main(String[] args)
o public static void main(String args[])
o public static void main(String... args)
Here Welcome.class file is not in binary format but in Byte Code Format. We can de compile
the Welcome.class file to convert it back to .java file
JAVA Welcome
Checking for version of JDK installed in your machine
While compiling and running the Java programs we need two softwares
o JAVAC.EXE Java Compiler
o JAVA.EXE Java Runtime
Note: If we print these values using print(), println () or printf () methods then its output will printed
as decimal number system
Floating Literals
Such numbers are of double by default
Use f or F as suffix with float type values
Examples
double x=123.55;
float y=123.55; //error
float =123.55F; //correct
Character Literals
Characters are enclosed in single quotes
char ch =='A';
Each character has corresponding ASCII value
char ch =65;
Characters from different languages have their Unicode values
char z=' \u0910';
String Literals
Enclosed in double quotes
Managed by String class
Example
String str ="Hello";
Boolean Literals
Can have true or false only
Examples
boolean married=false;
boolean rented=true;
Introduction to Packages
Special folders which contains related set of classes are called as packages
Examples
o java.lang package
Contains all commonly used classes String, Math, System, Integer, Character
etc.
It is default Package
o java.util package
Contains the collections and utility classes
LinkedList , Stack, Queue, Scanner, Date
o java.io package
Contains file and memory management related clsses
BufferedReader, InputStreamReader, File, FileReader , FileWriter etc.
Examples
import java.util.*;
import java.util.LinkedList;
import java.util.Scanner;
Terminologies in Java
Class
Instance
Reference
Constructor
What is class?
A set of specifications or blueprint about an entity describing all possible data members and
the methods to be applicable on that entity
Classes can be of two types
o User Defined classes
o Library classes
Use class keyword to create a class user defined class
What is instance?
A real entity created based on class specifications is called as instance
To create an instance, we require two things
o new keyword
o Constructor
An instance can be used to use the data members and the methods of that class
What is constructor?
What is reference?
Special variable which hold reference of an instance present somewhere in memory
It can be used to use the properties and methods of the class it is referring
Example
String s=new String("Hello");
Example
Write a program (ScannerTest.java) to input data of a student rollno (int), name (string), gender
(char) and fees (float). Show that data.
Hint: To input a character you can first input the data as string using next() method and then fetch its
first character using charAt() method of String class
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Roll No : ");
int rollno=sc.nextInt();
System.out.print("Name : ");
String name=sc.next();
System.out.print("Gender : ");
char gender=sc.next().charAt(0);
System.out.print("Fees : ");
float fees=sc.nextFloat();
System.out.printf("Roll No is %d, Name is %s, Gender is %c, Fees is
%f",rollno,name,gender,fees);
}
}
Note: When you try to input a string with space using nextLine() method, it may not work in
between. To handle such situations, you can use another method.
When we press a key from keyboard (System.in), a stream of bits get produced (A 01000001)
Java provides InputStreamReader class to read this stream of bits and convert into readable format
To read the data from buffer using readLine() method of BufferedReader class
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.*;
public class DataInputTest {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
System.out.print("Roll No : ");
int rollno=sc.nextInt();
System.out.print("Name : ");
String name=br.readLine();
System.out.print("Gender : ");
char gender=sc.next().charAt(0);
System.out.print("Fees : ");
float fees=sc.nextFloat();
System.out.printf("%s %d %c %f",name,rollno,gender,fees);
}
}
What is an array?
Special variable which allows to store multiple values of same data type in continues locations. Each
value or item get placed at some index number. Index number starts with 0.
Arrays in Java are treated as objects and created using new keyword.
Arrays provide length property to get size of array.
Example
int []num={6,1,2,9,12};
Test Case
Write a program having an array with sample values. Show sum of the values in the array.
public class SumArray {
public static void main(String[] args) {
int []num={5,1,8,9,12};
int sum=0;
for(int i=0;i<num.length;i++)
sum=sum+num[i];
System.out.println("Sum is "+sum);
}
}
Java provides a variant of for loop called as foreach loop where you can work on an array without
knowing length of it and without using array indexing.
Syntax
for(datatype variable: arrayname){
statements;
}
Test Case
Write a program (SumArray.java) having an array with sample values. Show sum of the values in the
array using foreach loop
public class SumArray {
public static void main(String[] args) {
int []num={5,1,8,9,12};
int sum=0;
for(int n:num)
sum=sum+n;
System.out.println("Sum is "+sum);
}
}
Example
int []num=new int[10]; //array of 10 integers
Test Case
Write a program (BigSmall.java) to create an array to store 10 integer values. Input 10 integer values
and show the smallest and biggest of given values.
import java.util.Scanner;
public class BigSmall {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int []ar=new int[10];
for(int i=0;i<ar.length;i++)
ar[i]=sc.nextInt();
int min,max;
min=max=ar[0];
for(int i=1;i<ar.length;i++){
if(ar[i]>max) max=ar[i];
if(ar[i]<min) min=ar[i];
}
System.out.printf("Smallest is %d and Biggest is %d",min,max);
}
}
Test Case
Write a program (BigSmall.java) to ask the user how many numbers to be input. Input that much of
integer type of values. Show the smallest and biggest of given values.
import java.util.Scanner;
public class BigSmall {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("How many numbers to input : ");
int num=sc.nextInt();
int []ar=new int[num];
System.out.printf("Enter %d integer values : ",num);
for(int i=0;i<ar.length;i++)
ar[i]=sc.nextInt();
int min,max;
min=max=ar[0];
for(int i=1;i<ar.length;i++){
if(ar[i]>max) max=ar[i];
if(ar[i]<min) min=ar[i];
}
System.out.printf("Smallest is %d and Biggest is %d",min,max);
}
}
Types of Array
Java provides two types of arrays
One Dimensional Array
Array of Array or Jagged Array
When an array can have only one row, it is called one dimensional array. All above examples
Are of one dimensional array.
When an array contains an array which refers to another array, it is called as array of array or Jagged
array. Such arrays allow to manage different number of columns in each row.
Example
Declare an array having 4 columns in first row, 5 columns in second row and 6 columns in third row.
Example
Declare an array of 3x4.
int [][]ar=new int[3][4];
Test Case
Write a program (ArrayOfArray.java) to create an array having 4 columns in first row, 5 columns in
second row and 6 columns in third row. Input that much of integer values and show of values in each
row.
import java.util.Scanner;
public class ArrayOfArray {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int [][]ar=new int[3][];
ar[0]=new int[4];
ar[1]=new int[5];
ar[2]=new int[6];
Test Case
Write a program (Matrix.java) having two arrays of 2x3 and 3x4. Input the integer type and show the
arrays in matrix format along with matrix multiplication.
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int [][]ar1=new int[2][3];
int [][]ar2=new int[3][4];
int [][]ar3=new int[2][4];
int i,j,k;
System.out.println("Enter 6 items in first array : ");
for(i=0;i<ar1.length;i++){
for(j=0;j<ar1[i].length;j++){
ar1[i][j]=sc.nextInt();
}
}
System.out.println("Enter 12 items in second array : ");
for(j=0;j<ar2.length;j++){
for(k=0;k<ar2[j].length;k++){
ar2[j][k]=sc.nextInt();
}
}
for(i=0;i<ar1.length;i++){
for(k=0;k<ar3.length;k++){
for(j=0;j<ar2.length;j++){
ar3[i][k]+=ar1[i][j]*ar2[j][k];
}
}
}
System.out.println("First Matrix is");
for(i=0;i<ar1.length;i++){
for(j=0;j<ar1[i].length;j++){
System.out.printf("%d\t",ar1[i][j]);
}
System.out.println();
}
System.out.println("Second Matrix is");
for(j=0;j<ar2.length;j++){
for(k=0;k<ar2[i].length;k++){
System.out.printf("%d\t",ar2[j][k]);
}
System.out.println();
}
System.out.println("Matrix multiplication : ");
for(i=0;i<ar1.length;i++){
for(k=0;k<ar1[i].length;k++){
System.out.printf("%d\t",ar2[i][k]);
}
System.out.println();
}
}
}
The java.lang.Throwable class act as the root for Java Exception Hierarchy
A Throwable class defines two child classes
o Exception
o Error
Exceptions are unexpected event that disturbs normal flow of the program. We can handle
such events.
An error is non-recoverable. We cannot handle them.
Types of Java Exceptions
● There are mainly two types of exceptions:
○ Checked
○ Unchecked
● Error is generally considered third type of exception
● Checked exceptions are checked at compile-time. The classes that directly inherit the
Throwable class except RuntimeException and Error are known as checked exceptions e.g.
IOException, SQLException, etc.
● Unchecked exceptions are not checked at compile-time, but they are checked at runtime. The
classes that inherit the RuntimeException are known as unchecked exceptions. For example,
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, etc.
● Error is irrecoverable but they are also unchecked kind of. Some example of errors are
OutOfMemoryError, VirtualMachineError, AssertionError etc.
Use try-catch block to try some statements and trap the runtime error
If we don’t know the kind of error may occur in the program code, use the parent classes
Throwable or Exception to handle all such exceptions
Here we can give some generalized message when a runtime error occurs
Tracking for Exception Name for Specialized Messaging
● We can track the exception class name that notified us about a runtime error
● Throwable class provides some common methods for all the exceptions
○ void printStackTrace()
■ Prints the complete error information
○ String getMessage()
■ Returns the error message only
● The program code may throw multiple kind of exceptions at different moments
● We can use multiple catch blocks to handle different types of exceptions
● Use Throwable class at the bottom to handle those exceptions that are not discovered yet
Test Case
● Create a class MyMath having a static method factorial() which takes a number as argument
and returns factorial of given number.
● If the value passed to factorial() method is in negative then throw an instance of Exception
class with a message “Sorry! Negative values not allowed”
● Create a class Demo with entry point. Input the data from user and show factorial of that
number.
● Handle the exceptions
What is String?
● An alphanumeric data is known a string. It can have alphabets, digits and special characters
● It can have zero or more characters
● Managed by java.lang.String class
● If a string is managed as literal we can use equality operator (==) or equals() or compareTo()
methods
● If a string is managed as instance use equals() or compareTo() methods
How to do the password masking in Java?
Using readPassword() method Console class. Provided in Java 6 and above.
What is immutable strings?
● A string that do not allow to change its contents is called as immutable strings
● String class is used to manage immutable strings
● When adding two strings with addition operator (+) it waste one memory space every time
due to immutable nature of String class
● Special classes which allows to change the data in same location are called as mutable classes
● Java provides two classes to manage mutable data
○ StringBuffer class (Java 1.0)
○ StringBuilder class (Java 5.0)
● Use append() method to append the data
● Use reverse() method to reverse a string
What is OOPs?
It is a system independent of any programming language to a goal “Building better and scalable
project management” using a set of components called as pillars of OOPs
1. Encapsulation
2. Abstraction
3. Polymorphism
4. Inheritance
1. Class
2. Instance
3. Reference
What is class?
A set of specifications or blueprint about an entity describing all possible data members and the
methods to be applicable on that entity.
Syntax
class <entityname>{
// members
}
1. Data Members
2. Methods
1. Special methods
a. Constructor
b. Finalizer
c. Setter
d. Getter
2. General methods
What is constructor?
What is setter?
What is getter?
Java provides a built-in reference called this to refer the current instance
Example
Entity Customer
Special Methods Constructor, setter for mobile, getter for data members