info@tutsfinder.in



Java Networking

Transmission of data from one system to another that connected via network.

Java programming language have java.net package for networking programs. This package contains all classes and interfaces that are used in to share resources via network.

These two protocols are used in networking –

1. TCP

2. UDP

TCP – Transmission Control Protocol

This is an Internet Protocol that provides for the reliable delivery of data from one host to another.

It is based on IP.

UDP – User Datagram Protocol

It is a connection-less protocol, that enables packets of data to be transmitted between application.

Some classes of java.net package –

Inet address- This class represents an Internet Protocol address as two fields: hostname and address.

URL- It is an acronym of Uniform Resource Locator .A standard for writing a text refrence to an arbitrary piece of data in www. A URL looks like 1 ”protocol://host/localinfo”.

Where protocol specifies a set of rules for communication.

For Example: TCP, FTP, Telnet, SMTP, POP etc.

URL Connection- This class represents the communication between the application and a URL.

Socket- java.net class implements socket .Socket is one endpoint between two way communications between two programs running on the internet.

Server Socket- This class allows to act like a server for connection oriented connections.

Datagram Packet – It is a connectionless socket that is used to implement a connection less delivery service.

Datagram Socket – This class represents socket for sending and receiving datagram packets.

Serialization

In short , serialization is converting a file into byte stream. The objects in the file is converted to the bytes for security purposes. We need to import java.io.serialization.

Deserialization is vice versa of serialization in which bytes stream is converted into files.

ObjectOutputStream.writeObject  Serialize the object and write the serialized object to a file.

ObjectInputStream.readObject  Read the file and deserializes the object.

Note :- We can skip the serialization for the variables in the file by using a Transient keyword.

Now , what is Transient variable?

These are not the part of serialization. During deserialization the transient variables values are set to default values. It is not used with static variables.

Program by extending thread class

  
class ThreadExtend extends Thread{
	public void run(){
		System.out.println("Thread Created...");
	}

	public static void main(String[] args){
	ThreadExtend obj=new ThreadExtend();
	obj.start();
	}
}
	


Output:

Thread Created...


Program by implementing runnable interface.

class ThreadImplement implements Runnable{
	public void run(){
		System.out.println("Thread Created...");
	}

	public static void main(String[] args){
	Thread obj = new Thread(new ThreadImplement());
	
obj.start();
	}
}

	


Output:

Thread Created...