0% found this document useful (0 votes)
91 views4 pages

Computer Netwaok Short Notes

The Java Virtual Machine (JVM) is an abstract computer that runs compiled Java programs independently of the underlying hardware or operating system. It provides a layer of abstraction between Java programs and platforms. The JVM is lean because it is small and designed to run on many devices, and ambitious because it aims to run programs everywhere. It handles memory management through garbage collection which frees memory from objects no longer in use. Events in Java are represented by EventObject subclasses that carry event information to notify listeners of user interactions or other occurrences.

Uploaded by

Dev Verma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views4 pages

Computer Netwaok Short Notes

The Java Virtual Machine (JVM) is an abstract computer that runs compiled Java programs independently of the underlying hardware or operating system. It provides a layer of abstraction between Java programs and platforms. The JVM is lean because it is small and designed to run on many devices, and ambitious because it aims to run programs everywhere. It handles memory management through garbage collection which frees memory from objects no longer in use. Events in Java are represented by EventObject subclasses that carry event information to notify listeners of user interactions or other occurrences.

Uploaded by

Dev Verma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

S hort Note On Java V irtual Finalize: This method is used for garbage

collection. This method will get execute before


Event: An action or occurrence, often generated
Machine? The Java Virtual Machine, or JVM, is an Garbage Collection is done, because it release by the user, to which the program might respond—for
abstract computer that runs compiled Java programs. The example, key presses, button clicks, or mouse
the resource which are hold by the program.
JVM is “virtual” because it is generally implemented in movements.
Finally: This method is used for in the
software on top of a “real” hardware platform and operating
system. All Java programs are compiled for the JVM. exception handling mechanism. Once try block
Therefore, the JVM must be implemented on a particular is executed, then finally block is must to
platform before compiled Java programs will run on that execute. This block will release the resource
hold by the try block. Programming with events
platform. Events are not exclusive to the Java platform; they
The JVM plays a central role in making Java portable. It Final: The final keyword is used declaring
existed before Java and were popularized by graphical
provides a layer of abstraction between the compiled Java variables as constant
user interfaces like Windows and the X Window
program and the underlying hardware platform and An applet is a small Internet-based program written System. These graphic-intensive systems are driven by
operating system. The JVM is central to Java’s portability in Java, a programming language for the Web, which the user with events. In contrast, with the traditional
because compiled Java programs run on the JVM, can be downloaded by any computer. The applet is programming model, the application controls program
independent of whatever may be underneath a particular also able to run in HTML. The applet is usually flow. This flow is predetermined by the statements and
JVM implementation. embedded in an HTML page on a Web site and can be conditions that are coded
What makes the JVM lean and mean? The JVM is lean executed from within a browser. In Java, events are generated by objects. An event is
because it is small when implemented in software. It was
designed to be small so that it can fit in as many places as garbage collection (GC) is a form of represented by a java.util.EventObjectsubclass that
automatic memory management. It is a special case carries event information. There are subclasses for
possible — places like TV sets, cell phones, and personal each kind of event. At a minimum, they hold a
computers. The JVM is mean because it of its ambition. of resource management, in which the limited resource
being managed is memory. The garbage collector, or reference to the object that generated the event
“Ubiquity!” is its battle cry. It wants to be everywhere, and (the source of the event), but each subclass defines
its success is indicated by the extent to which programs just collector, attempts to reclaim garbage, or memory
occupied by objects that are no longer in use by additional information appropriate for the event.
written in Java will run everywhere. A Java Virtual Machine (JVM) enables a set of
the program. Garbage collection was invented by John
internet McCarthy around 1959 to solve problems in Lisp.[1][2] computer software programs and data structures to
use a virtual machine model for the execution of other
The Internet is a global system of Garbage collection is often portrayed as the opposite computer programs andscripts. The model used by a
interconnected computer networks that use the of manual memory management, which requires the JVM accepts a form of computer intermediate
standard Internet Protocol Suite (TCP/IP) to serve programmer to specify which objects to deallocate and language commonly referred to as Java bytecode. This
billions of users worldwide. It is a network of return to the memory system. However, many systems language conceptually represents the instruction set of
networks that consists of millions of private, public, use a combination of the two approaches, and other a stack-oriented, capability architecture. Sun
academic, business, and government networks, of techniques such as stack allocation and region Microsystems states there are over 4.5 billion JVM-
local to global scope, that are linked by a broad array inference can carve off parts of the problem. There is enabled devices
of electronic, wireless and optical networking an ambiguity of terms, as theory often uses the A JVM can also execute bytecode compiled from
technologies. The Internet carries a vast range terms manual garbage collection and automatic programming languages other than Java. For
of information resources and services, such as the garbage collection rather than manual memory example, Ada source code can be compiled to execute
inter-linked hypertextdocuments of the World Wide management and garbage collection, and does not on a JVM. JVMs can also be released by other
Web (WWW) and the infrastructure to restrict garbage collection to memory management, companies besides Oracle (the developer of Java) —
support electronic mail. rather considering that any logical or JVMs using the "Java" trademark may be developed by
physical resource may be garbage collected. other companies as long as they adhere to the JVM
Most traditional communications media including specification published by Oracle and to related
telephone, music, film, and television are reshaped or contractual obligations.
redefined by the Internet, giving birth to new services
such as Voice over Internet Protocol (VoIP) and IPTV. What Is JDK? Java DataBase Connectivity, commonly
Newspaper, book and other print publishing are referred to as JDBC, is an API for the Java
adapting to Web site technology, or are reshaped programming language that defines how a client may
JDK is the acronym for Java Development Kit-
into blogging and web feeds. The Internet has enabled access a database. It provides methods for querying
essentially a Java platform, consisting of the API
or accelerated new forms of human interactions and updating data in a database. JDBC is oriented
classes, a Java compiler, and the Java Virtual Machine
through instant messaging, Internet forums, and social towards relational databases. A JDBC-to-ODBC bridge
interpreter. The JDK is used to compile
networking. Online shopping has boomed both for enables connections to any ODBC-accessible data
Java applications and applets. The most current
major retail outlets and small artisans and source in the JVM host environment.
version is the J2SE.
traders. Business-to-business and financial
jDBC allows multiple implementations to exist and be
services on the Internet affect supply chains across If you use J2SE 1.2 and later to develop applications, used by the same application. The API provides a
entire industries you are using what's known as the Java 2 Platform. mechanism for dynamically loading the correct Java
The latest Java 5 or J2SE 1.5 is Sun’s most ambitious packages and registering them with the JDBC Driver
The Internet Protocol (IP) is the upgrade that has several enhancements to the Java Manager. The Driver Manager is used as a connection
principal communications protocol used for language that did not exist so far. factory for creating JDBC connections.
relaying datagrams (packets) across An object is a set of data combined with methods
an internetwork using theInternet Protocol Suite. for manipulating JDBC connections support creating and executing
Responsible for routing packets across network that data.  statements. These may be update statements such
boundaries, it is the primary protocol that establishes An object is made from a class; a class is the blueprint as SQL's CREATE, INSERT, UPDATE and DELETE, or
the Internet. for they may be query statements such as SELECT.
the object. Additionally, stored procedures may be invoked
IP is the primary protocol in the Internet Layer of the
through a JDBC connection.
Internet Protocol Suite and has the task of delivering
For creating object one need to follow the below steps
datagrams from the source host to the destination host
solely based on their addresses. For this purpose, IP
create an object: Name for object :- Syntax: An exception is an event, which occurs during
defines addressing methods and structures for the execution of a program, that disrupts the
<ClassName> <ClassVariableName>;
datagram encapsulation.
normal flow of the program's instructions.
Historically, IP was the connectionless datagram instantiation of object: Space in memory for object:
service in the original Transmission Control Program Syntax:- <ClassVariableName> = new <ClassName>();
introduced by Vint Cerf and Bob Kahn in 1974, the When an error occurs within a method, the method
other being the connection-oriented Transmission initializing of object: Defining value for object Using
constructor: Syntax- <ClassVariableName> = new creates an object and hands it off to the runtime
Control Protocol (TCP). The Internet Protocol Suite is
therefore often referred to as TCP/IP. <ClassName>(initializing value);  system. The object, called an exception object,
The Internet Protocol is responsible for addressing contains information about the error, including its
An Object is a key to understanding object Oriented
hosts and routing datagrams (packets) from a source
technology.
type and the state of the program when the error
host to the destination host across one or more IP occurred. Creating an exception object and
.it is  an instance of a class.
networks. handing it to the runtime system is called throwing
It is an entity that shares 2 characteristics state and
IP addressing and routingPerhaps the most behavior. an exception.After a method throws an exception,
complex aspects of IP are IP addressing and routing. Variables are state of an object. the runtime system attempts to find something to
Addressing refers to how end hosts become assigned Methods are behavior of an object
IP addresses and how subnetworks of IP host handle it. The set of possible "somethings" to
addresses are divided and grouped together. IP routing
Threads handle the exception is the ordered list of methods
is performed by all hosts, but most importantly by A thread is in process in execution within a that had been called to get to the method where the
internetwork routers, which typically use either interior program. Within a program each thread
error occurred.
gateway protocols (IGPs) or external gateway defines a separate path of execution. 
protocols (EGPs) to help make IP datagram forwarding Creation of a thread
decisions across IP connected networks. A thread can be created in two ways Catch or Specify Requirement
a) By implementing the Runnable interface. Valid Java programming language code must
The Runnable interface consists of only one honor the Catch or Specify Requirement. This
 web browser or Internet browser is method - the run method. The run method has
a software application for retrieving, presenting, and a prototype of means that code that might throw certain
traversing information resources on the World Wide
Code: exceptions must be enclosed by either of the
Web. An information resource is identified by
a Uniform Resource Identifier (URI) and may be a web public void run(); following:
page, image, video, or other piece of content.
[1] b) By extending the class Thread. 
 Hyperlinks present in resources enable users to
easily navigate their browsers to related resources.
Execution of a thread  A try statement that catches the
Although browsers are primarily intended to access To execute a thread, the thread is first created exception. The try must provide
the World Wide Web, they can also be used to access and then the start() method is invoked on the
information provided by Web servers inprivate thread. Eventually the thread would execute
a handler for the exception, as
networks or files in file systems. Some browsers can and the run method would be invoked. The described in Catching and
also be used to save information resources to file example below illustrates the two methods of
systems.
Handling Exceptions.
thread creation. You should note that the run
Difference between final, finally and method should not be invoked directly.  A method that specifies that it
finalize in Java? can throw the exception. The
method must provide
a throws clause that lists the discussion of the concepts behind routing  Objects
protocols, see: Routing.  Instance
exception, as described  Method
inSpecifying the Exceptions The term routing protocol may refer specifically  Message Parsing
In this chapter we will look into the concepts
Thrown by a Method. to one operating at layer three of the OSI model,
Classes and Objects.
which similarly disseminates topology information  Object - Objects have states and
between routers. behaviors. Example: A dog has
Code that fails to honor the Catch or Specify states-color, name, breed as well
Although there are many types of routing as behaviors -wagging, barking,
Requirement will not compile. protocols, three major classes are in widespread eating. An object is an instance of
use on IP networks: a class.
Applet  Class - A class can be defined as a
template/ blue print that
Here is an example of a  Interior gateway routing via link- describe the behaviors/states
that object of its type support.
state routing protocols, such
simple APPLET tag: as OSPF and IS-IS Objects in Java:
 Interior gateway routing via path Let us now look deep into what are objects. If
vector or distance vector protocols, such we consider the real-world we can find many
<applet objects around us, Cars, Dogs, Humans etc. All
as RIP, IGRP and EIGRP
code="MyApplet.class"  Exterior gateway routing. BGP v4 is
these objects have a state and behavior.
If we consider a dog then its state is . name,
width=100 the routing protocol used by the breed, color, and the behavior is . barking,
height=140></applet> public Internet. wagging, running
If you compare the software object with a real
Many routing protocols are defined in documents world object, they have very similar
called RFCs.[1][2][3][4] characteristics.

This tells the viewer or The specific characteristics of routing protocols



include
browser to load the applet  the manner in which they either
prevent routing loops from forming or
whose compiled code is in break them up if they do
Internet Architecture Board
MyApplet.class (in the same  the manner in which they select
preferred routes, using information about The Internet Architecture Board (IAB) is the
directory as the current hop costs committee charged with oversight of the technical
 the time they take to converge and engineering development of the Internet by
HTML document), and to set  how well they scale up the Internet Society (ISOC).
the initial size of the applet to  Java is a programming language and It oversees a number of Task Forces, of which
computing platform first released by Sun the most important are the Internet Engineering
100 pixels wide and 140 Microsystems in 1995. It is the underlying Task Force (IETF) and the Internet Research
technology that powers state-of-the-art Task Force (IRTF).
pixels high. programs including utilities, games, and
business applications. Java runs on more The body which eventually became the IAB was
Email than 850 million personal computers created originally by the United States
worldwide, and on billions of devices Department of Defense's Defense Advanced
worldwide, including mobile and TV Research Projects Agency with the name Internet
Email, also sometimes written as e-mail, is simply devices. Configuration Control Board during 1979; it
the shortened form of electronic mail, a protocol  Why do I need Java? eventually became the Internet Advisory
for receiving, sending, and storing electronic There are lots of applications and Board during September, 1984, and then
messages. Email has gained popularity with the websites that won't work unless you
the Internet Activities Board during May, 1986
have Java installed, and more are
spread of the Internet. In many cases, email has (the name was changed, while keeping the same
created every day. Java is fast, secure,
become the preferred method of communication. and reliable. From laptops to acronym). It finally became the Internet
datacenters, game consoles to scientific Architecture Board, under ISOC, during January,
supercomputers, cell phones to the 1992, as part of the Internet's transition from a
Electronic mail, commonly called email, e- Internet, Java is everywhere! U.S.-government entity to an international, public
mail or e.mail, is a method of  Java is a programming entity.
exchanging digital messages from an author language originally developed Polymorphism is the ability of an object to
to one or more recipients. Modern email take on many forms. The most common use of
by James Gosling at Sun
operates across the Internet or polymorphism in OOP occurs when a parent class
Microsystems (which is now a
other computer networks. Some early email reference is used to refer to a child class object.Any
subsidiary of Oracle Corporation) java object that can pass more than on IS-A test is
systems required that the author and the and released in 1995 as a core considered to be polymorphic. In Java, all java
recipient both be onlineat the same time, a component of Sun objects are polymorphic since any object will pass
la instant messaging. Today's email systems Microsystems' Java platform. The the IS-A test for their own type and for the class
are based on a store-and-forward model. Object.It is important to know that the only
language derives much of
Email servers accept, forward, deliver and possible way to access an object is through a
its syntax from Cand C++ but has a
store messages. Neither the users nor their reference variable. A reference variable can be of
simpler object model and fewer low-
computers are required to be online only one type. Once declared the type of a
level facilities. Java applications are
simultaneously; they need connect only reference variable cannot be changed.
typically compiled to bytecode (clas public interface Vegetarian{}
briefly, typically to an email server, for as long Ex-
s file) that can run on any Java public class Animal{}
as it takes to send or receive messages. Virtual Machine (JVM) regardless public class Deer extends Animal
Protocols of computer architecture. Java is a implements Vegetarian{}
general-purpose, concurrent, class- Abstraction refers to the ability to make a class
based, object-oriented language abstract in OOP. An abstract class is one that
 IMAP that is specifically designed to have cannot be instantiated. All other functionality of the
 POP3 as few implementation class still exists, and its fields, methods, and
dependencies as possible. It is constructors are all accessed in the same manner.
 SMTP You just cannot create an instance of the abstract
intended to let application
 UUCP developers "write once, run class.
 X400 anywhere". Java is currently one of

Routing protocol the most popular programming


languages in use, and is widely Encapsulation is one of the four fundamental
OOP concepts. The other three are inheritance,
used from application software to
A routing protocol is a protocol that specifies polymorphism, and abstraction.
web applications.
how routers communicate with each other,
disseminating information that enables them to
Encapsulation is the technique of making the fields
select routes between any two nodes on
Java is an Object Oriented Language. As a in a class private and providing access to the fields
acomputer network, the choice of the route being via public methods. If a field is declared private, it
done by routing algorithms. Each router has a language that has the Object Oriented feature
Java supports the following fundamental cannot be accessed by anyone outside the class,
priori knowledge only of networks attached to it thereby hiding the fields within the class. For this
concepts:
directly. A routing protocol shares this information  Polymorphism reason, encapsulation is also referred to as data
first among immediate neighbors, and then  Inheritance hiding.
throughout the network. This way, routers gain  Encapsulation
knowledge of the topology of the network. For a  Abstraction
 Classes
An interface is a collection of abstract
 UDP: UDP stands for User Datagram
Protocol, a connection-less protocol
There are some important differences between an
applet and a standalone Java application, including
methods. Aclass implements an interface, thereby that allows for packets of data to be the following:
inheriting the abstract methods of the interface. transmitted between applications.

 An applet is a Java class that extends


An interface is not a class. Writing an interface is This tutorial gives good understanding on the the java.applet.Applet class.
similar to writing a class, but they are two different following two subjects:
concepts. A class describes the attributes and
behaviors of an object. An interface contains
behaviors that a class implements.  A main() method is not invoked on an
1. Socket Programming: This is most applet, and an applet class will not
widely used concept in Networking define main().
and it has been explained in very
Unless the class that implements the interface is detail.
abstract, all the methods of the interface need to be
defined in the class.  Applets are designed to be embedded
within an HTML page.

an interface is different from a class


2. URL Processing: This would be
covered separately. Click here to  When a user views an HTML page
in several ways, including: learn about URL Processing in Java that contains an applet, the code for
language. the applet is downloaded to the
user's machine.
 You cannot instantiate an interface.
3. java provides built-in support
for multithreaded programming.  A JVM is required to view an applet.
 An interface does not contain any A multithreaded program contains The JVM can be either a plug-in of
constructors. two or more parts that can run the Web browser or a separate
concurrently. Each part of such a runtime environment.
program is called a thread, and each
thread defines a separate path of
 All of the methods in an interface are
execution.  The JVM on the user's machine
abstract.
creates an instance of the applet
class and invokes various methods
4. A multithreading is a specialized form during the applet's lifetime.
 An interface cannot contain instance
fields. The only fields that can appear
of multitasking. Multitasking threads
require less overhead than What is Java?
in an interface must be declared both Java is:
multitasking processes.
static and final.
 Object Oriented
 Platform independent:

 An interface is not extended by a
class; it is implemented by a class.
5. Life Cycle of a 
Simple
Secure
Thread:A thread goes  Architectural- neutral
through various stages in its life  Portable
 An interface can extend multiple cycle. For example, a thread is born,  Robust
interfaces. started, runs, and then dies.  Multi-threaded
Following diagram shows complete  Interpreted
life cycle of a thread.
 High Performance
packages are used in Java in-order to prevent  Distributed
naming conflicts, to control access, to make
searching/locating and usage of classes, interfaces, 6. Above mentioned stages are  Dynamic
enumerations and annotations easier etc. explained here: 
 The Internet Group
Management
A Package can be defined as a grouping of related 7. New: A new thread begins its life
types(classes, interfaces, enumerations and cycle in the new state. It remains in
Protocol (IGMP) is
annotations ) providing access protection and name this state until the program starts the a communications protocol used
space management. thread. It is also referred to as a born by hosts and adjacent routers on IP
thread. networks to establish multicast
group memberships.
Some of the existing packages in Java are::  IGMP is an integral part of the IP
8. Runnable: After a newly born thread multicast specification. It is
is started, the thread becomes analogous
 java.lang - bundles the fundamental runnable. A thread in this state is
to ICMP for unicast connections.
classes considered to be executing its task.
IGMP can be used for
online streaming video and gaming,
 Waiting: Sometimes a thread
and allows more efficient use of
 java.io - classes for input , output resources when supporting these
functions are bundled in this package transitions to the waiting state while
the thread waits for another thread to types of applications.
perform a task.A thread transitions  IGMP is used on IPv4 networks.
back to the runnable state only when Multicast management
another thread signals the waiting on IPv6 networks is handled
thread to continue executing. by Multicast Listener
Discovery (MLD) which
the term network programming refers uses ICMPv6 messaging as
to writing programs that execute across multiple  Timed waiting: A runnable thread can
opposed to IGMP's bare IP
devices (computers), in which the devices are all enter the timed waiting state for a
connected to each other using a network. specified interval of time. A thread in encapsulation.
this state transitions back to the

The java.net package of the J2SE APIs contains a


runnable state when that time
interval expires or when the event it First Java Program:
is waiting for occurs.
collection of classes and interfaces that provide the Let us look at a simple code that
low-level communication details, allowing you to
write programs that focus on solving the problem at
would print the words Hello World.
hand.  Terminated: A runnable thread enters
the terminated state when it
completes its task or otherwise
public class MyFirstJavaProgram{
The java.net package provides support for the two terminates.
common network protocols: /* This is my first java program.
* This will print 'Hello World' as the output
*/
 TCP: TCP stands for Transmission
Control Protocol, which allows for public static void main(String []args){
reliable communication between two An applet is a Java program that runs in a Web System.out.println("Hello World"); // prints Hello World
applications. TCP is typically used browser. An applet can be a fully functional Java }
over the Internet Protocol, which is application because it has the entire Java API at its }
referred to as TCP/IP. disposal.
communications, or the The following is an array is declared
JVM has run out of with 2 elements. Then the code tries
memory. to access the 3rd element of the
array which throws an exception.

Some of these exceptions are caused


by user error, others by programmer // File Name :
error, and others by physical ExcepTest.java
resources that have failed in some import java.io.*;
manner. public class ExcepTest{

Constructors: To understand how exception public static void


handling works in Java, you need to main(String args[]){
When discussing about classes one of the
most important sub topic would be understand the three categories of try{
constructors. Every class has a exceptions: int a[] = new
constructor. If we do not explicitly write a int[2];
constructor for a class the java compiler
builds a default constructor for that class.  Checked exceptions: A
checked exception is an System.out.println("Access
exception that is typically element three :" + a[3]);
Each time a new object is created at }
a user error or a problem
least one constructor will be invoked. catch(ArrayIndexOutOfBounds
that cannot be foreseen by
The main rule of constructors is that Exception e){
the programmer. For
they should have the same name as
example, if a file is to be
the class. A class can have more
opened, but the file cannot System.out.println("Excepti
than one constructor.
be found, an exception on thrown :" + e);
occurs. These exceptions }
Example of a constructor is given cannot simply be ignored
below: at the time of compilation.
System.out.println("Out of
the block");
class Puppy{
 Runtime exceptions: A }
public puppy(){ runtime exception is an }
} exception that occurs that
public puppy(String name){ probably could have been
// This constructor has one parameter, avoided by the
} programmer. As opposed
}
to checked exceptions,
runtime exceptions are
ignored at the time of
compliation.
Creating an Object:
As mentioned previously a class provides the
blueprints for objects. So basically an object is
created from a class. In java the new key word is  Errors: These are not
used to create new objects. exceptions at all, but
problems that arise
There are three steps when creating an object from beyond the control of the
a class: user or the programmer.
Errors are typically ignored
 Declaration . A variable declaration in your code because you
with a variable name with an object can rarely do anything
type.
about an error. For
example, if a stack
 Instantiation . The 'new' key word overflow occurs, an error
is used to create the object. will arise. They are also
ignored at the time of
 Initialization . The 'new' keyword is compilation.
followed by a call o a constructor.
This call initializes the new object

An exception is a problem that


arises during the execution of a
program. An exception can occur for
many different reasons, including the
following:

 A user has entered invalid


data.

 A file that needs to be


opened cannot be found.
Example:
 A network connection has
been lost in the middle of

You might also like