Google News
logo
Java URL's
Uniform Resource Locator
1) URL is a class present in the java.net package. 

2) By using the URL we are accessing some information present in the world wide web. 

Example of URL is:
http://www.freetimelearning.com/java/java-urls.php

The URL contains information like
a. Protocol to use http://
b. Server name/IP address www.freetimelearning.com
c. File name or directory name java/java-urls.php

3) To crate the object for URL we have to use the fallowing syntax
a. URL obj=new URL(String protocol, String host, int port, String path);
b. URL obj=new URL(String protocol, String host, String path);
URL program
import java.util.*; 
import java.net.*; 
import java.io.*; 
import java.net.*; 
class Test 
{ 
public static void main(String[] args) throws Exception 
{ 
URL url=new URL("http://www.freetimelearning.com:10/index.php"); 
System.out.println("protocal is:"+url.getProtocol()); 
System.out.println("host name is:"+url.getHost()); 
System.out.println("port number is:"+url.getPort()); 
System.out.println("path is:"+url.getPath()); 
System.out.println(url); 
} 
}
Output :
protocal is:http
host name is:www.freetimelearning.com
port number is:10
path is:/index.php
http://www.freetimelearning.com:10/index.php
Communication using networking :
In the networking it is possible to do two types of communications.
1) Connection oriented(TCP/IP communication)
2) Connection less(UDP Communication)
Connection Oriented :
a) In this type of communication we are using combination of two protocols TCP,IP.
b) In this type of communication the main purpose of the TCP is transferred in the form of packets between the source and destination. And the main purpose of the IP is finding address of a particular system.
To achieve the fallowing communication the java peoples are provided the fallowing classes.
a. Socket
b. ServerSocket
Application Layer :
Takes the data from the application and sends it to the TCP layer.
TCP Protocol:-
it will take the data which is coming from Application Layer and divides in to small units called Packets. Then transfer those packets to the next layer called IP. The packet contains group of bytes of data.
IP:-
It will take the packets which is coming from TCP and prepare envelop called frames hence the frame contains the group of packets. Then it will identify the particular target machine on the basis of the IP address and sent that frames to the physical layer.
Physical Layer:-
Based on the physical medium it will transfer the data to the target machine.
Connection Less :- (UDP)
1) UDP is a protocol by using this protocol we are able to send data without using Physical Connection.
2) This is a light weight protocol because no need of the connection between the client and server .
3) This is very fast communication compare to the TCP/IP communication.
4) This protocol not sending the data inn proper order there may be chance of missing the data.
5) This communication used to send the Audio and Video data if some bits are lost but we are able to see the video and images we are getting any problems.
To achieve the UDP communication the java peoples are provided the fallowing classes.
1. DataGrampacket.
2. DataGramSocket.