WT Notes Unit I
WT Notes Unit I
WT Notes Unit I
Identify target user: Identify the user of the website by doing market
research.
Make our design portable : To be successful, website design should be
portable and accessible across different browsers, operating systems, and
computer platforms. Designers should test the website in a different
environment whether they look same to all their users.
Design for low bandwidth : Web pages in websites should be accessible
at any connection speeds. If a page is downloaded slowly then users will
leave the website before they see the content.
Plan for clear presentation and easy access to information :
Presentation of the information on the website must be clear and easily
accessible to the user.
Create smooth transitions: Plan to create a unified look among the
sections and pages of site. Reinforce the identifying elements of the site
and create smooth transitions from one page to another.
Any software development project, a methodology should be followed to ensure
project consistency and completeness.
History of Web and Internet
The World Wide Web is a system of interlinked hypertext documents accessed
via the Internet. Web is a huge collection of pages of information linked to each
other around the globe.
History of WWW:
WWW was created by Sir Tim Berners Lee in 1989 at CERN in Geneva.
In 1990 , the first text only browsers were set up and CERN scientists could
access hypertext files and other information at CERN. HTML was based on
a subset of the standard generalized markup language (SGML). To transfer
HTML documents to remote sites a new protocol was devised called HTTP
(HyperText Transfer Protocol).
In the fall of 1991, conferences around the world started hearing about the
promise but sparks still were not flying.
In 1993, there were only about 50 websites worldwide. A browser that
allowed users to take advantage of the web’s graphical capabilities was
developed at the National center for SuperComputing application (NCSA) .
NCSA called the browser Mosaic
Protocols Governing Web
Protocol: A protocol is a set of rules that is used to communicate applications to
each other.
OR
A protocol is the interface required for communicating the different applications.
Protocols which are a set of rules that help in governing the way a particular
technology will function for communication. In other words, it can be said that the
protocols are digital languages implemented in the form of networking algorithms.
There are different networks and network protocols, user's use while surfing.
Classifications
Specific
Measurable
Attainable
Realistic
Time limited
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
Market research
Focus group
Understanding intranet audiences
Determine the scope: By supporting documents and client’s approval.
Budget:
Computer
Connection - Phone Line, Cable, DSL, Wireless,...
Modem
Network Software - TCP/IP
Application Software - Web Browser, Email,...
Internet Service Provider (ISP)
1 Electronic Mail
Used to send electronic message over the internet.
Telnet
2
Used to log on to a remote computer that is attached
to internet.
Newsgroup
3
Offers a forum for people to discuss topics of
common interests.
Internet Relay Chat (IRC)
4
Allows the people from all over the world to
communicate in real time.
Mailing Lists
5
Used to organize group of internet users to share
common information through e-mail.
Internet Telephony (VoIP)
6
Allows the internet users to talk across internet to
any PC equipped to receive the call.
Instant Messaging
7
Offers real time chat between individuals and group
of people. Eg. Yahoo messenger, MSN messenger.
Information Retrieval Services
There exist several Information retrieval services offering easy access to
information present on the internet. The following table gives a brief introduction
to these services:
S.N. Service Description
Web Services
Web services allow exchange of information between applications on the web.
Using web services, applications can easily interact with each other.
The web services are offered using the concept of Utility Computing.
World Wide Web (WWW)
WWW is also known as W3. It offers a way to access documents spread over the
several servers over the internet. These documents may contain texts, graphics,
audio, video, hyperlinks. The hyperlinks allow the users to navigate between the
documents.
Video Conferencing
Video conferencing or Video teleconferencing is a method of communicating by
two-way video and audio transmission with help of telecommunication
technologies.
Modes of Video Conferencing
Point-to-Point
Multi-point
This mode of conferencing connects more than two locations through Multi-point
Control Unit (MCU).
Terminologies :-
The terminologies in distributed client/server architecture’s are as follows-
The client server computing works with a system of request and response.
The client sends a request to the server and the server responds with the
desired information.
The client and server should follow a common communication protocol so
they can easily interact with each other. All the communication protocols
are available at the application layer.
A server can only accommodate a limited number of client requests at a
time. So it uses a system based to priority to respond to the requests.
Denial of Service attacks hindera servers ability to respond to authentic
client requests by inundating it with false requests.
An example of a client server computing system is a web server. It returns
the web pages to the clients that requested them.
Difference between Client Server Computing and Peer to Peer
Computing
The major differences between client server computing and peer to peer
computing are as follows:
All the required data is concentrated in a single place i.e. the server. So it is
easy to protect the data and provide authorization and authentication.
The server need not be located physically close to the clients. Yet the data
can be accessed efficiently.
It is easy to replace, upgrade or relocate the nodes in the client server
model because all the nodes are independent and request data only from
the server.
All the nodes i.e clients and server may not be build on similar platforms yet
they can easily facilitate the transfer of data.
Disadvantages of Client Server Computing
The different disadvantages of client server computing are −
If all the clients simultaneously request data from the server, it may get
overloaded. This may lead to congestion in the network.
If the server fails for any reason, then none of the requests of the clients
can be fulfilled. This leads of failure of the client server network.
The cost of setting and maintaining a client server model are quite high.
What is Java?
Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle)
in the year 1995. James Gosling is known as the father of Java. Before Java, its
name was Oak. Since Oak was already a registered company, so James Gosling
and his team changed the Oak name to Java.
It is owned by Oracle, and more than 3 billion devices run Java.
It is used for:
Note: If you have compiled the exact code, you need to save the file as
HelloWorld.java. It's because the name of the class and file name should match in
Java. Also, some online compilers only accept the class named Main.
Things to take away
Every valid Java Application must have a class definition (that matches the
filename).
The main method must be inside the class definition.
The compiler executes the codes starting from the main function.
Components Of Java Programming Language
A Java Programmer writes a program in a human-readable language called
Source Code. Therefore, the CPU or Chips never understand the source code
written in any programming language.
These computers or chips understand only one thing, which is called machine
language or code. These machine codes run at the CPU level. Therefore, it would
be different machine codes for other models of CPU.
However, you need to worry about the machine code, as programming is all about
the source code. The machine understands this source code and translates them
into machine understandable code, which is an executable code.
All these functionalities happen inside the following 3 Java platform components:
Java Development kit (JDK)
JDK is a software development environment used for making applets and Java
applications. The full form of JDK is Java Development Kit. Java developers can
use it on Windows, macOS, Solaris, and Linux. JDK helps them to code and run
Java programs. It is possible to install more than one JDK version on the same
computer.
JDK contains tools required to write Java programs and JRE to execute
them.
It includes a compiler, Java application launcher, Appletviewer, etc.
Compiler converts code written in Java into byte code.
Java application launcher opens a JRE, loads the necessary class, and
executes its main method.
Java Virtual Machine (JVM):
JRE contains class libraries, JVM, and other supporting files. It does not
include any tool for Java development like a debugger, compiler, etc.
It uses important package classes like math, swing, util, lang, awt, and
runtime libraries.
If you have to run Java applets, then JRE must be installed in your system.
Operator in Java
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Misc Operators
The Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that
they are used in algebra. The following table lists the arithmetic operators
Assume integer variable A holds 10 and variable B holds 20, then
Miscellaneous Operators
There are few other operators supported by Java Language.
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
instanceof Operator
This operator is used only for object reference variables. The operator checks
whether the object is of a particular type (class type or interface type). instanceof
operator is written as −
( Object reference variable ) instanceof (class/interface type)
Data type
There are two data types available in Java −
Primitive Data Types
Reference/Object Data Types
There are eight primitive datatypes supported by Java. Primitive datatypes are
predefined by the language and named by a keyword. Let us now look into the
eight primitive data types in detail.
byte
int
long
float
double
boolean
char
Reference Datatypes
Local Variable
A variable declared inside the body of the method is called local variable. You can
use this variable only within that method and the other methods in the class aren't
even aware that the variable exists.
A local variable cannot be defined with a "static" keyword.
Instance Variable
A variable declared inside the class but outside the body of the method, is called
instance variable. It is not declared as static.It is called instance variable because its
value is instance specific and is not shared among instances.
Static variable
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something, for
example, shape, triangle, rectangle, etc.
In Java, we use method overloading and method overriding to achieve
polymorphism.
Another example can be to speak something; for example, a cat speaks
meow, dog barks woof, etc.
Abstraction
Hiding internal details and showing functionality is known as abstraction.
For example phone call, we don't know the internal processing.In Java, we
use abstract class and interface to achieve abstraction.
Inheritance
When one object acquires all the properties and behaviors of a parent object,
it is known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism.
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully
encapsulated class because all the data members are private here.
Method in Java
In general, a method is a way to perform some task. Similarly, the method in
Java is a collection of instructions that performs a specific task. It provides the
reusability of code. We can also easily modify code using methods. In this
section, we will learn what is a method in Java, types of methods, method
declaration, and how to call a method in Java.
Method Declaration
The method declaration provides information about method attributes, such as
visibility, return-type, name, and arguments. It has six components that are known
as method header, as we have shown in the following figure.
Types of Method
There are two types of methods in Java:
Predefined Method
User-defined Method
Predefined Method
In Java, predefined methods are the method that is already defined in the Java class
libraries is known as predefined methods. It is also known as the standard library
method or built-in method. We can directly use these methods just by calling them
in the program at any point. Some pre-defined methods are length(), equals(),
compareTo(), sqrt(), etc.
User-defined Method
The method written by the user or programmer is known as a user-defined method.
These methods are modified according to the requirement.
Inheritance
Inheritance in Java is a mechanism in which one object acquires all the properties
and behaviors of a parent object.Why use inheritance in java
extends Keyword
extends is the keyword used to inherit the properties of a class.
Single Inheritance Example
When a class inherits another class, it is known as a single inheritance. In the
example given below, Dog class inherits the Animal class, so there is the single
inheritance.
File: TestInheritance.java
1class Animal{
2 void eat(){System.out.println("eating...");}
3}
4class Dog extends Animal{
5 void bark(){System.out.println("barking...");}
6}
7class TestInheritance{
8public static void main(String args[]){
9Dog d=new Dog();
10d.bark();
11d.eat();
12}}
Output:
barking...
eating...
File: TestInheritance2.java
1class Animal{
2 void eat(){System.out.println("eating...");}
3}
4class Dog extends Animal{
5 void bark(){System.out.println("barking...");}
6}
7class BabyDog extends Dog{
8 void weep(){System.out.println("weeping...");}
9}
10class TestInheritance2{
11 public static void main(String args[]){
12 BabyDog d=new BabyDog();
13 d.weep();
14 d.bark();
15 d.eat();
16}}
Output:
weeping...
barking...
eating...
File: TestInheritance3.java
1class Animal{
2 void eat(){System.out.println("eating...");}
3}
4class Dog extends Animal{
5 void bark(){System.out.println("barking...");}
6}
7class Cat extends Animal{
8 void meow(){System.out.println("meowing...");}
9}
10class TestInheritance3{
11 public static void main(String args[]){
12 Cat c=new Cat();
13 c.meow();
14 c.eat();
15 //c.bark();//C.T.Error
16}}
Output:
meowing...
eating...
Exception Handling
As you can see from the image above, the Throwable class is the root class in the
hierarchy.
Note that the hierarchy splits into two branches: Error and Exception.
Java Exception Types
The exception hierarchy also has two branches: RuntimeException and
IOException.
1. RuntimeException
A runtime exception happens due to a programming error. They are
also known as unchecked exceptions.
These exceptions are not checked at compile-time but run-time. Some of
the common runtime exceptions are:
You can think about it in this way. “If it is a runtime exception, it is your
fault”.
2. IOException
An IOException is also known as a checked exception. They are checked
by the compiler at the compile-time and the programmer is prompted to
handle these exceptions.
Some of the examples of checked exceptions are:
Output
ArithmeticException => / by zero
In the example, we are trying to divide a number by 0. Here, this code
generates an exception.
To handle the exception, we have put the code, 5 / 0 inside the try block.
Now when an exception occurs, the rest of the code inside the try block is
skipped.
The catch block catches the exception and statements inside the catch block
is executed.
If none of the statements in the try block generates an exception, the catch
block is skipped.
2. Java finally block
In Java, the finally block is always executed no matter whether there is an
exception or not.
The finally block is optional. And, for each try block, there can be only one
finally block.
1class Main {
2 public static void main(String[] args) {
3 try {
4 // code that generates exception
5 int divideByZero = 5 / 0;
6 }
7
8 catch (ArithmeticException e) {
9 System.out.println("ArithmeticException => " + e.getMessage());
10 }
11 finally {
12 System.out.println("This is the finally block");
13 }
14 }
15}
Output
ArithmeticException => / by zero
This is the finally block
In the above example, we are dividing a number by 0 inside the try block.
Here, this code generates an ArithmeticException.
The exception is caught by the catch block. And, then the finally block is
executed.
java.io.FileNotFoundException:
test.txt (The system cannot find the file specified)
Advantages of multithread:
The users are not blocked because threads are independent, and we can
perform multiple operations at times
As such the threads are independent, the other threads won't get affected if
one thread meets an exception.
Following are the stages of the life cycle −
New − A new thread begins its life cycle in the new state. It remains in this
state until the program starts the thread. It is also referred to as a born
thread.
Runnable − After a newly born thread is started, the thread becomes
runnable. A thread in this state is considered to be executing its task.
Waiting − Sometimes, a thread transitions to the waiting state while the
thread waits for another thread to perform a task. A thread transitions back to
the runnable state only when another thread signals the waiting thread to
continue executing.
Timed Waiting − A runnable thread can enter the timed waiting state for a
specified interval of time. A thread in this state transitions back to the
runnable state when that time interval expires or when the event it is waiting
for occurs.
Terminated (Dead) − A runnable thread enters the terminated state when it
completes its task or otherwise terminates.
In this tutorial, we will learn about Java input/output streams and their types.
In Java, streams are the sequence of data that are read from the source and written
to the destination.
An input stream is used to read data from the source. And, an output stream is
used to write data to the destination.
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
For example, in our first Hello World example, we have used System.out to print a
string. Here, the System.out is a type of output stream.
Similarly, there are input streams to take input.
We will learn about input streams and output streams in detail in the later tutorials.
Before exploring various input and output streams lets look at 3 standard or
default streams that Java has to provide which are also most common in use:
1. System.in: This is the standard input stream that is used to read characters
from the keyboard or any other standard input device.
2. System.out: This is the standard output stream that is used to produce the
result of a program on an output device like the computer screen.
3. System.err: This is the standard error stream that is used to output all the
error data that a program might throw, on a computer screen or any standard
output device.
Types of Streams
Depending upon the data a stream holds, it can be classified into:
Byte Stream
Character Stream
Byte Stream
Byte stream is used to read and write a single byte (8 bits) of data.All byte stream
classes are derived from base abstract classes called InputStream and OutputStream.
InputStream:
InputStream is an abstract class of Byte Stream that describe stream
input and it is used for reading and it could be a file, image, audio, video,
webpage, etc. it doesn’t matter. Thus, InputStream read data from source
one item at a time.
OutputStream:
OutputStream is an abstract class of Byte Stream that describes stream
output and it is used for writing data to a file, image, audio, etc. Thus,
OutputStream writes data to the destination one at a time.
Difference between InputStream and OutputStream
InputStream OutputStream
1. It is an abstract class that describes Stream Input. 1. It is an abstract class that describes Stream Output.
2. InputStream Read data from the source once at a 2. InputStream Write data from the source once at a
time. time.
FileInputStream FileOutputStream
ByteArrayInputStream ByteArrayOutputStream
FilterInputStream FilterOutputStream
ObjectInputStream ObjectOutputStream
In these types the most important and mostly used In these types the most important and mostly used
type is FileInputStream. type is FileOutput Stream.
Character Stream
In Java, characters are stored using Unicode conventions (Refer this for details).
Character stream automatically allows us to read/write data character by character.
Though it has many classes, the FileReader and the FileWriter are the most popular
ones. FileReader and FileWriter are character streams used to read from the source
and write to the destination respectively
Stream class Description
PrintWriter This contains the most used print() and println() method
Java Applet
An applet is a Java program that can be embedded into a web page. It runs inside
the web browser and works at client side. An applet is embedded in an HTML page
using the APPLET or OBJECT tag and hosted on a web server.
Important points :
Four methods in the Applet class gives you the framework on which you build any
serious 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.
Event handling
Changing the state of an object is known as an event. For example, click on button,
dragging mouse etc. The java.awt.event package provides many event classes and
Listener interfaces for event handling.
generated when
mouse is dragged,
moved,clicked,presse
MouseEvent MouseListener
d or released and also
when it enters or exit
a component
generated when input
KeyEvent is received from KeyListener
keyboard
generated when
ItemEvent check-box or list item ItemListener
is clicked
generated when
MouseWheelEven
mouse wheel is MouseWheelListener
t
moved
generated when
window is activated,
WindowEvent deactivated, WindowListener
deiconified, iconified,
opened or closed
generated when
component is hidden, ComponentEventListene
ComponentEvent
moved, resized or set r
visible
generated when
component is added
ContainerEvent ContainerListener
or removed from
container
generated when
FocusEvent component gains or FocusListener
loses keyboard focus
Characteristics
It is a set of native user interface components.
It is very robust in nature.
It includes various editing tools like graphics tool and imaging tools.
It uses native window-system controls.
It provides functionality to include shapes, colors and font classes.
Advantages
It takes very less memory for development of GUI and executing programs.
It is highly stable as it rarely crashes.
It is dependent on operating system so performance is high.
It is easy to use for beginners due to its easy interface.
Disadvantages
The buttons of AWT does not support pictures.
It is heavyweight in nature.
Two very important components trees and tables are not present.
Extensibility is not possible as it is platform dependent
AWT Classes
The AWT framework contains many classes and interfaces using which we
can create GUIs. The AWT package is java.awt. Some of the frequently used
AWT classes are listed below:
Various classes in java.awt package are arranged in a hierarchy as shown
below:
Component and Container
The Component is the abstract root class for many GUI control classes.
Container is a sub class of Component class. The Component and various
Container classes are arranged in a hierarchy as shown below:
Component
Container
Container is a sub class of the Component class which can be used to hold
other components. A Container object can hold other Containers also. A
Container is responsible for laying out (positioning) the components.
Panel
Panel class is a concrete sub class of the Container class. A Panel object is a
window without title bar, menu bar and border. Panel is the super class of
Applet class and is capable of holding other components or containers.
Window
Frame
Canvas
Frame Class
The Frame class is used to create standard windows. Following are two
Frame class constructors:
Frame()
Frame(String title)
void setSize(int width, int height) – Used to specify the width and height of
the frame window.
void setTitle(String title) – Used to set the title of the frame window.