Program No.1: Statement: Program To Simulate The Functioning of Lamport's Logical Clock. Logic
Program No.1: Statement: Program To Simulate The Functioning of Lamport's Logical Clock. Logic
Logic:
Conditions:
Implementation Rule:
Program:
IMPORT JAVA.UTIL.*;
PUBLIC CLASS LAMPORTCLOCK
{
INT C;
PUBLIC LAMPORTCLOCK()
{
C = 1;
}
PUBLIC INT GETVALUE()
{
RETURN C;
}
PUBLIC VOID TICK()
{
C = C + 1;
}
PUBLIC VOID SENDACTION()
{
C = C + 1;
}
PUBLIC VOID RECEIVEACTION(INT SRC, INT SENTVALUE)
{
C = (UTIL.MAX(C, SENTVALUE)) + 1;
}
}
PROGRAM NO. 2
Statement: Program to display the IP address and host name of the system.
Program:
import java.net.*;
class InetDemo
{
public static void main(String args[])
{
try
{
InetAddress ia = InetAddress.getLocalHost();
System.out.println("The IP address of local host is "+ia);
ia=InetAddress.getByName(args[0]);
System.out.println("the IP address of "+args[0]+"is"+ia);
}
catch(UnknownHostException ue)
{
System.out.println("There is an error "+ue);
}
}
}
Output:
C:\JAVA\BIN>javac InetDemo.java
Statement: Program to obtain the information about the (a) Host, (b) Port, (c) Protocol.
Program:
import java.lang.* ;
import java.io.*;
import java.net.*;
class ud1
{
public static void main(String args []) throws
MalformedURLException
{
URL url = new URL("http://www.yahoo.com");
try
{
System.out.println("host name is " + url.getHost());
System.out.println("port no. is " + url.getPort());
System.out.println("protocol used is " + url.getProtocol());
}
catch (Exception e)
{
System.out.println("error"+e);
}
}
}
Output :
C:\JAVA\BIN>javac ud1.java
C:\JAVA\BIN>java ud1 yahoo.com
host name is www.yahoo.com
port no. is
protocol used is http