Internet Programming Unit 1 (In-Complete)
Internet Programming Unit 1 (In-Complete)
It is a global network of networks. Or Internet is the largest computer network in the world connecting
billions of computers.
It uses the standard internet protocol suit called TCP/IP to serve billions of user worldwide.
History of Internet The first internet was developed by “Advance Research Product Agency”[ARPA] of US
department of defense in 1969. It has called as ARPA Net.
Internet Intranet
It is a wide network of computers and it’s open for Intranet is also a network of computers design for
all.
Internet itself contains a large no of intranets. aIt specific
can be group of users.from internet but with
accessed
restrictions.
The number of users who use internet is unlimited. The number of users is limited.
The visitor’s traffic is unlimited. The traffic allowed is also limited
Internet contains different sources of information Intranet contain only specific group of information
and
It is aiscollection
available for all.
of various LAN, WAN and MAN. Mostly any of LAN or MAN or WAN
TCP = Transmission control protocol
IP = Internet protocol
Internet protocol : The internet protocol is the language that computers used to communicate over
the internet.
Example: 216.27.16.136
Example: 11011000.00011011.00111101.10001000
If we add all the position together we get 32. so the IP address is always 32 bits.
The most of the people type the domain name in the browser than IP address as it is easy to
remember name than numbers.
Domain Names :
Domain names are textual names given to the notes on the internet. It is in the form of words
separated by dots[periods].
The last position of domain name represents top level domain or first level domains . There are several
hundred top levels of domain name as follows.
A unique two letter combinations for every country like .in for India, Au for Australia, Uk for united
kindom.etc.
Sub Domain : Sub domains are the third level domains that are used to organize the website contain in a
systematic manner.
They are just like folders and under root directly. ex : http:||www.kar.nic.in
The web is a system of interlink hyper text documents access via internet.
The web uses http protocol to transmit data over the internet.
The web utilizes browser like google chrome to access the web documents called web pages that are
linked to each other via hyperlinks.
Web Browser :
A web browser is a software application used to locate and display the web pages
. It is able to retrieve, find, view and send information over the internet.
When request is made by our computer then that computer is called client and when the request gets
serve by another computer then that computer is called server.
Some of the popular web browser all internet explorer, opera, mozillafirefox.
The browser understands the programming languages used towrite web pages and converts then to
readable and viewable documents.
Web browser knows how to go to a web server on the internet and request a page.
Java Evolution
Java History
.
touch-sensitive screen.
1993 The World Wide Web (WWW) appeared on the Internet and transformed the teit-based
Internet Into a graphical-rich environment. The green Protect team came up with the
idea of developing Web applets (tiny programs ) using the new language that could run
on all types of computers connected to Internet
1994 The team developed a Web browser Called ‘Hot Java to locate and run applets programs
on Internet. Hot java demonstrated the power of the new language. thus making it
instantly popular among the Internet users.
1995 Oak was renamed “Java”. due to some legal snags. Java is just a name and is not an
acronym. Many popular companies including Netscape and Microsoft announced their
support to java.
1996 Java established itself not only as a leader for internet programming but also as a
gencral-purpose, object-oriented programming language. Sun releases Java
development kit 1.0
1997 Sun releases Java development kit 1.1 (JDK 1.1)
1998 Sun releases Java 2 with venison 1.2 of the Software Development Kit (SDK 1.2
1999 Sun releases Java 2 Platform, Standard Edition (12SF) and Enterprise Edition (J2EE).
2000 J2SE with SDK 1.3 was released
2002 J2SE with SDK 1.4 was released
The most significant contribution of Java over other languages is its portability. Java programs can
be easily moved from one computer system to another, anywhere and anytime. Changes and
upgrades in operating systems, processors and system resources will not force any changes in
Java programs. This is the reason why Java has become a popular language for programming on
Internet which interconnects different kinds of systems worldwide, We can download a Java
applet from a remote computer onto our local system via Internet and execute it locally. This
makes the Internet an extension of the user’s basic system providing practically unlimited number of
accessible applets and applications.
Java ensures portability in two ways. First, the java compiler generates code bytecode instructions
that can be implemented on any machine. Secondly, the size of the primitive data types
are machine- independent
3. Object-Oriented
Java ta a irue obje.nentd 1anguage. Almost eveything in Jara is an object. All program code and data
reside within objects and classes. Java comes with an extcnsivc sct of classes, arranged in packages,
that we can use in our programs by inheritance, The object model in Java is simple and easy to
extend
Security becomes an important issue for a language that is used for programming on Internet.
Threat of viruses and abuse of resources arc everywhere. Java systems not only verify all memory
access but also ensure that no viruscs are communicated with an applet. The absence of pointers
in Java ensures that programs cannot gain access to memory locations without proper
authorization
5. Distributed
Java is designed as a distributed language for creating applications on networks, It has the ability to
share both data and programs. Java applications can open and access remote objects on internet as
easily as they can do in a local system. This enables multiple programmers at multiple remote
locations to collaborate and work together on a single project
6. Simple, Small and Familiar
Java is a small and simple language. Many features of C and C+ that are either redundant or
sources of unreliable code are not part of Java. For example, Java does not use pointers,
preprocessor header files. goto statement and many others. It also eliminates operator
overloading and multiple inheritance.
Familiarity is another striking feature of Java. To make the language look familiar to the existing
programmers. it was modelled on C and C--+ languages. Java uses many constructs of C and
C++ and therefore Java code “looks Like a C++” code, In fact, java is a simplified version of
C++.
8. High Performance
Java performance is impressive for an interpreted language. mainly due to the use of intcrmediate
bytecode. According to Sun Java speed is comparable to the native C.’C’+ Java architecture is
.
also designed to reduce overheads during runtime Furthur. the incorporatioii of multithreading
enhances the overall execution speed of Java programs.
IMP
How Java Differs from C and C++
Although Java was modelled after C and C++ languages. it differs from C and C++ in many ways. Java
does not incorporate a number of features available in C and C++. For the benefit of C and C+ +
programmers, we point out here a few major differences between C+ + and Java languages.
Java and C
Java is a lot like C but the major difference between Java and C is Java is an object oriented
language and has mechanism to define classes and objects. In an effort to build a simple
and safe language, the Java learn did not include some of the C features in Java.
1. Java does not contain the data types struct and union
2. Java does not define the type modifiers keywords auto, extern. register, signed, and unsigned.
3. Java does not include the C unique statement keywords sizeof. and typcdef
4. Java does not support an explicit pointer type.
5. Java does not have a preprocessor and therefore we cannot use #define. # include, and # lfdef
statemenis
6. Java requires that functions with no arguments must be declared with empty parenthesis and
not with the void keyword as done in C.
7. Java adds labelled break and continue statements
Java and C++
Internet users can also set up their Web sites containing Java applets that could be used by other
remote users of Internet, The ability of Java applets to hitch a ride on the Information
Superhighway has madc Java a unique programming language for the Internet. In fact. due to this
java popularly known as Internet language.
Applet Tag
Request
Web Server
USERS
1. Hot Java
2. Netscape Navigator
3. Internet Explorer
HotJava
HotJava is the Web browser from Sun Microsystems that enables the display of
interactive content on the Web, using the Java language. Hot Java is written entirely in
Java and demonstrates the capabilities of the Java programming language.
Netscape Navigator
Netscape Navigator is a general-purpose browser that can run Java appicts. With versions
available for Windows 95, NT, Solaris and Apple Macintosh. Netscape Navigator is one of
the most widely used browsers today.
Netscape Navigator has many usefull features such as visual display about downloading
process and indication of the numt’cr bytes downloaded. Ii also supports JavaScript, a
scripting language used in HTMl. document
Internet Explorer
Internet Explorer is another popi1ar browser developed by Microsoft for Windows 95, NT
and XI’ Workstations. Both the Navigator and Explorer use tool bars. icons, menus and dialog
boxes for easy navigation. Explorer uses a just-in-time (JIT) compiler which greatly increases
the speed of execution.
IMP
Hardware and Software Requirements
Java is currently supported on Windows 95. Windows NT, Windows XP, Sun Solaris.
Macintosh. and UNIX machines, Though, the programs and examples in this hook were tested
under Windows 95, the most popular operating system today, they can be implemented on
any of the above systems.
The minimum hardware and software requirements for Wmdows 95 version of Java are as
follows;
• IBM-compatible 486 system • A hard drive
• Minimum of 8 MB memory • A CD-ROM drive
• Windows 95 software • A Microsoft-compatible mouse
• A Windows-compatible sound card, if necessary
Java Support Systems
Java support systems consists of the following
JAVAC
javac is the compiler for the Java programming language; it's used to compile .java file. It
creates a class file which can be run by using java command.
EXAMPLE
c:\javac TestFile.java
JAVA
The Java Standard Library (or API) includes hundreds of classes and methods grouped
into several functional package. Most commonly used packages arc:
Language Support Package: A collection of classes and methods required for
implementing basic features of Java.
1. Stand-alone applications arc programs written in Java to carry out certain tasks on a stand-
alone local computer. In fact. Java can be used to develop programs for all kinds of applications.
which earlier, were developed using languages like C and C++
We can develop applets for doing everything from simple animated graphics to complex
games and utilities. Since applet’s are embedded in an HTML document and run inside a Web
page. creating and naming applets are more complex than creating an application.
JAVA
SOURCE
CODE
JAVA COMPILER
OUTPUT OUTPUT
Class SampleOne
{ public static void main (String args[])
{ System.out.println(“Java is Better than C.”):
}
}
Class Declaration
The first line class Samp1eOne declares a class, which as an object-oriented
construct. As stated earlier, Java is a true object-oriented language and therefore, every
thing must be placed inside a class, class is a keyword and declares that a new class
definition follows. SampleOne is a Java identifier that specifies the name of the class to be
defined
Opening Brace
Every class definition in Java begins with an opening brace { and cnd with a matching
closing brace “} appearing in the last line in the example.
“,
Public Public keyword is a access specifier that declares main method and
thereby making it accessible to all other classes
Static This keyword declares this method as one that belongs to entire class
and not a part of any object of the class
Void The type modifier void states that main method does not return any
value but prints some text to the scrren or performs calculations
JAVA PROGRAM STRUCTURE
Java program may coati many classes of which only one class defines a main method. Classes
contain data members and methods that operate on the data members of the class,
Methods may contain data type declarations and executable statements. To write a Java
program, we first define classes and then put them together. A Java program may contain one
or more sections as below.
}
Documentation Section
The documentation section comprises a set of comment lines giving the name of the program the
author and other details, which the programmer would like to refer to at a Later stage.
Comments must explain and greatly help in maintaining the program
Package Statement
This statement declares package name and informs the compiler that the classes
defined here belongs to this package.
Example : package student;
Import statement
Most statements contain expressions. which describe the actions earned out on data. Smallest
individual units inaprogram are known as tokens. The compiler recognizes them for building
up expressions and statements.
Java language includes five types of tokens.
They are:
• Reserved Keywords
• Identifiers
• Literals
• Operators
• .Separators
Keywords
Keywords are essential parts of a language definition. Java language has reserved 50 words as
keywords. These keywords, combined with operators and separators according to syntax, form
definition of the Java language. Since keywords have specific meaning in Java, we cannot use them as
names for variables, classes, methods and so on All keywords arc to be written in lower-case letters.
Identifiers
Identifiers are programmer-designed tokens. They arc used for naming classes, methods,
variables. objects, labels, packages ans interfaces in a program.
Java identifiers follow the following rules.
I They can have alphabets, digits. and the underscore and dollar sign characters.
2. They must not begin with a digit.
3. Uppercase and lowercase letters are distinct,
4. They can be of any length.
Examples:
average
sum
Literals
Literals in Java are a scqucnce of characters digits. letters. and other characters that represent constant
values to be stored in variables. Java language specifies five major types of lilerals.
They are:
• Integer literals
• Floating point literals
• Character literals
• String literals
• Boolean literals
Each of them has a type associated with it. The type describes how thc values behave arid how they are
stored.
Operators
An operator is a symbol that takes one or more arguments and operates on them to produce a result.
Separators
Separators are symbols used to indicate where groups of code are divided and arranged,
Java Statements
The statements in Java are like sentences in natural languages. A statements is an executable
combination of tokens ending with a semicolon ( ; ) mark. Statements are usually executed in
sequence in the order in which they appear,
Java Virtual Machine
All language compilers translate source code into machine code for a specific computer. Java
compiler also does the same thing. Then, how does Java achieve architecture neutrality? The
answer is that the Java compiler produces an intermediate code known as bytecode for a
machine that does not exist. This machine is called the Java Virtual Machine and it
exists only inside the computer memory. it is a simulated computer within the computer
and does all major functions of a real computer. Below figure illustrates
the process of compiling a Java program into byte code which is also referred to as virtual machine
code
PROCESS OF COMPILATION
The virtual machine code is not machine specific. The machine specific code (known as machine code)
is generated by the Java interpreter by acting as an intermediary between the virtual machine
and the real machine as shown in Fig. below
BYTE CODE JAVA MACHINE
INTEPRETER CODE
VIRTUAL MACHINE REAL MACHINE
Command line arguments are parameters that are supplied to the application program at the time of
invoking it for execution. We can write Java programs that can receive and use the arguments provided
in the command line. e.g. public static void main (String args[]). args is declared as an array of strings and
arguments provided in the command line are passed to the array args as its elements.
The user enters command-line arguments when invoking the application and specifies
them after the name of the class to be run. EXAMPLE java Echo JAVA IS EASY
Constants
Constants in Java refer to fixed values that do not change during the execution of a program.
Java supports several types of constants as illustrated in Fig. below
Integer Constants
An integer constant refers to a sequence of digits. Thcrc are three types of integers namely,
decimal integer. octal integer and hexa decimal integer.
Decimal integer consist of a set of digits. 0 through 9. preceded by an optional minus sign. Valid
examples of decimal integer constants are
Embedded spaces. commas, and non-digit characters arc not permitted between digits.
For example.
15 750 20.000 $1000 are illegal numbers
JAVA CONSTANTS
Following are the examples of valid hex integers. 0x2 OX9F Oxbcd Ox
BITWISE OPERATORS
Bitwise operators are operators that perform operations on data that are in the form of bits ir 0 and 1.
Let us suppose the bitwise AND operation of two integers 12 and 25.
00001100
& 00011001
________
#include <stdio.h>
int main()
{
int a = 12, b = 25;
printf("Output = %d", a&b);
return 0;
}
Output
Output = 8
Bitwise OR operator |
The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1. In C
Programming, bitwise OR operator is denoted by |.
00001100
| 00011001
________
#include <stdio.h>
int main()
{
int a = 12, b = 25;
printf("Output = %d", a|b);
return 0;
}
Output
Output = 29
00001100
^ 00011001
________
#include <stdio.h>
int main()
{
int a = 12, b = 25;
printf("Output = %d", a^b);
return 0;
}
Output
Output = 21
~ 00100011
________
11011100 = 220 (In decimal)
For any integer n, bitwise complement of n will be -(n+1). To understand this, you should have
the knowledge of 2's complement.
2's Complement
Two's complement is an operation on binary numbers. The 2's complement of a number is equal
to the complement of that number plus 1. For example:
The bitwise complement of 35 is 220 (in decimal). The 2's complement of 220 is -36. Hence, the
output is -36 instead of 220.
Output = -36
Output = 11
Right shift operator shifts all bits towards right by certain number of specified bits. It is denoted
by >>.
Left shift operator shifts all bits towards left by certain number of specified bits. It is denoted by
<<.
printf("\n");
return 0;
}