Hash Map Example using iteration



To use Hash Map using Java

// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
packagecom.allinalljava;

importjava.util.HashMap;
importjava.util.Iterator;
importjava.util.Map;
importjava.util.Set;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class HashMapSample {
public static void main (String [] args)
{
Map m = new HashMap ();
Employee e = new Employee ("ram", 50000.0);
m.put ("123", e);
e = new Employee ("ganes", 30000.0);
m.put ("456", e);
e = new Employee ("rajesh", 49750.0);
m.put ("758", e);
Set entries = m.entrySet ();
Iterator iter = entries.iterator ();
while (iter.hasNext ())
{
Map.Entry me = (Map.Entry) iter.next ();
System.out.print (me.getKey () + " ");
e = (Employee) me.getValue ();
System.out.println (e.getName () + " " + e.getSalary ());
}
System.out.println ("Map size = " + m.size ());
System.out.println ("Empty: " + m.isEmpty ());
m.clear ();
System.out.println ("Map size = "+ m.size ());
System.out.println ("Empty: " + m.isEmpty ());
}
}


Employee.java

// Comment

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.allinalljava;

/**
 *
 * @author allinalljava.blogspot.com
 */
import java.util.*;
class Employee
{
private String name;
private double salary;
Employee (String name, double salary)
{
this.name = name;
this.salary = salary;
}
String getName ()
{
return name;
}
double getSalary ()
{
return salary;
}
}

Output

123 ram 50000.0
456 ganes 30000.0
758 rajesh 49750.0
Map size = 3
Empty: false
Map size = 0
Empty: true
raja P Web Developer

Mother Board Driver for Tamil Nadu Government free Laptop (Lenovo B460)



Free  Laptop distributed by Tamil Nadu  Government contains several features. Education wise all the e-book content available in Laptop.Due to this students can improve their technical skills level. It is properly categorized based on the students level for all arts, polytechnic and engineering student first year syllabus eBook’s (such as Engineering Drawing ,Math, Communication Skills ,Botany , Zoology ,Computer Science Material is Also Available .Students those who are not get their laptop can copy these contents from the laptop those who have already got. It may improve you lot at beginning of college days.

Things to do After Getting Free Laptop

             Mother board Drive for Lenovo B460 is available in your laptop  c: drive itself. After getting laptop the Student have to make its back up in CD  or Pen drive. Better  by external portable DVD Drive for the laptop .It will use full for you in many way .For installing you OS. Laptop itself contains Two OS (BOSS as Linux OS, Windows). Important thing that all student while using pen drive for copying any data better use BOSS operating system and please check files whether there is any unwanted file in that folder or not. This may help you to avoid virus from your system. Don’t use laptop with low charge or by plugging with power after battery is full. It might make your battery weak. When battery reach 20 % plug charger and when it 100% just unplug it. It make your laptop life long. Better buy USB Keyboard and mouse for  typing and other mouse handling it makes you more convenient .It will accept all type of internet facility. Tamil Nadu government has done a great job for the student to improve  education level. For any doubt related laptop just comment here.

Free Download Mother Board Drivers ForTN Govt Laptops

 Download all Model Tamil Nadu Government free laptop Mother Board Drivers From this Links.
raja P Web Developer

Synchronization Using Bit Stuffing


To write a C program to perform the  BIT STUFFING using linux enviroinment.


  Step1: Start the program.
  Step2: Get the messages and check the message for five repeated “1” value.
  Step3: If it is true then add “0” as next value.
  Step4: Print the sending messages one by one.
  Step5: Stop the program.

Source code 


// Comment
#include<stdio.h>
#include<string.h>
main()
{
char b[30]={0,0},c[30]={0,0},a[40]="01111110",e[40]="01111110";
int i,j=0,cnt=0,n;
printf("enter the string");
scanf("%s",b);
n=strlen(b);
for(i=0;i<n;i++)
{
c[j]=b[i];
if(b[i]='1')
cnt++;
else
cnt=0;
if(cnt==5)
{
c[++j]='0';
cnt=0;
}
j++;	
}
printf("after bit stuffing \n");
strcat(a,c);
strcat(a,e);
printf("%s",a);
}


Output

[t03it    @localhostt03it   ]$ cc bitstuff.c
[t03it    @localhostt03it   ]$./a.out
enter the string 111111
after bit stuffing
01111110111110101111110
 
raja P Web Developer

Cyclic Redundency Check in linux


To write a C program to perform the  CRC computation using linux environment

Step1: Start the program.
Step2: Declare the variables and array of values.
Step3: Get the bits of data of the original values.
Step4: Get the divisor binary values for the original data.
Step5: By using for loop perform the process of CRC.
Step6: Finally the sending data’ s are printed.
Step7: Stop the program.

Source Code
 
// Comment
#include<stdio.h>
#include<string.h>
void xor(char a[10],char b[10],int len)
{
int i;
for(i=1;i<len;i++)
{
if(a[i]==b[i])
a[i-1]='0';
else
a[i-1]='1';
}
a[i]='\0';
}
main()
{
char a1[10],a2[10],t1[10],t2[10],t[5],res[15],c[15];
int n,len,tn,i;
printf("enter input string");
scanf("%s",a1);
printf("enter divisor");
scanf("%s",a2);
n=strlen(a1);
len=strlen(a2);
strcpy(res,a1);
for(i=0;i<len-1;i++)
{
c[i]='0';
}
c[i]='\0';
strcat(a1,c);

tn=strlen(a1);
strcpy(t1,a2);
for(i=0;i<len;i++)
{
t2[i]='0';
}
t2[i]='\0';
strncpy(t,a1,len);
for(i=len;i<=tn;i++)
{
xor(t,a2,len);
len=strlen(a2);
strcpy(res,a1);
for(i=n;i<n+len-1;i++)
{
a1[i]='0';
}
a1[i]='\0';
tn=strlen(a1);
strcpy(t1,a2);
for(i=0;i<len;i++)
{
t2[i]='0';
}
t2[i]='\0';
strncpy(t,a1,len);
for(i=len;i<=tn;i++)
{
xor(t,a2,len);
if(t[0]=='1')
strcpy(a2,t2);
else

strcpy(a2,t2);
t[len-1]=a1[i];
t[len]='\0';
}
strcat(res,t);
printf("the result is%s\n",res);
}
}






Output  
[t03it    @localhostt03it   ]$ cc crc.c
[t03it    @localhostt03it   ]$./a.out
enter input string 111011111
enter divisor 1101
the result is 111011111000000

raja P Web Developer

Stock Market Using Corba


To write a program to develop a middle-ware component for retrieving Stock Market Exchange information using CORBA.

  • Creating a module which contains a set of interface program and save it as a SimpleStocks.idl makes sure that module and interface name is different.
  • Next declare the implementation file with ImplBase concept & contains details about stock maintenance.
  • Create a server program  that initialize the ORB name the server object & bind the server object with the implementation file now server is ready.
  • Create a client program by initialize the ORB. Make sure the name of server object and client object declared resembles the frame.
  • Then provide the input to the client program and obtain the suitable output corresponding to it.

Compile & Execution Steps:

  • idlj -fall -oldImplBase SimpleStocks.idl
  • javac StockMarketImpl.java SimpleStocks\*.java
  • javac StockMarket server.java SimpleStocks\*.java
  • javac StockMarket client.java SimpleStocks\*.java
  • start orbd -ORBInitialPort 1050
  • start java StockMarket Server -ORBInitialPort 1050
  • java StockMarket client -ORBInitialPort 1050 50.
Source code

Simplestock.idl
// Comment
module Simplestock
{
interface stockmarket
{
float get_price(in string symbol);
};
};


stockmarketimpl.java
// Comment
import org.omg.CORBA.*;
import simplestocks.*;
public class stockmarketimpl extends _stockmarketImplBase
{
 public float get_price(String symbol)
  {
  float price=0;
  for(int i=0;i<symbol.length();i++)
  {
   price+=(int)symbol.charAt(i);
  }
   price/=5;
   return price;
  }
   public stockmarketimpl()
  {
   super();
  }
 }


Stockmarketserv.java
// Comment
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simplestocks.*;
public class stockmarketserv
{
 public static void main(String args[])
 {
  try
  {
     ORB orb=ORB.init(args,null);
     stockmarketimpl stockmarketimpl=new stockmarketimpl();
     orb.connect(stockmarketimpl);
     org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService");
     NamingContext ncRef=NamingContextHelper.narrow(objRef);
     NameComponent nc=new NameComponent("NASDAQ"," ");
     NameComponent path[]={nc};
     ncRef.rebind(path,stockmarketimpl);
     System.out.println("Stockmarket server is ready");
     Thread.currentThread().join();
    }
    catch(Exception e)
    {
     e.printStackTrace();
    }
   }
  }


stockmarketcli.java
// Comment
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simplestocks.*;
public class stockmarketcli
{
 public static void main(String args[])
 {
  try
  {
   ORB orb=ORB.init(args,null);
   NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
   NameComponent path[]={new NameComponent("NASDAQ"," ")};
   stockmarket market=stockmarketHelper.narrow(ncRef.resolve(path));
   System.out.println("Rate of the company is"+market.get_price(args[2]));
   }
   catch(Exception e)
   {
    e.printStackTrace();
    }
   }
  }

Output Screen
 
raja P Web Developer

Weather Forecast Information Using CORBA


To develop the application program in CORBA to illustrate the temperature server.

  •  Creating a module which contains a set of interface program and save it as a Simple Temperature.idl makes sure that module and interface name is different.
  • Next declare the implementation file with IMPL Base concepts & contains details about temperature display.
  • Create a server program that initialize the ORB name the server object &bind the server object with the implementation file.
  • Now server is ready.
  • Create a client program by initialize the ORB. make sure the name of the server object and client object declared reassembles the fram.
  • Then provide the input to the client program and obtain the suitable output corresponding to it.
Compile & Execution Steps


  •    idlj -fall -oldImplBase SimpleTemperature.idl
  •    javac Temperatureimpl.java SimpleTemperature\*.java
  •    javac Temperatureserver.java SimpleTemperature\*.java
  •     javac Temperatureclient.java SimpleTemperature\*.java
  •       start orbd -ORBInitialPort 1050
  •      start java Temperature server -ORBInitialport 1050
  •       server is ready.
  •   java Temperature client -ORBInitialport 1050 30
 
SimpleTemperature.idl

// Comment
module SimpleTemperature
{
interface Temperature
{
string get_tmp(in float a);
};
}; 

Temperatureimpl.java

// Comment

import org.omg.CORBA.*;
import SimpleTemperature.*;
public class Temperatureimpl extends _TemperatureImplBase
{
public String get_tmp(float a)
{
String c;
if (a<0)
c="----------Too cool----------";
else if(a<=10)
c="----------cool----------";
else if(a<=20)
c="----------MODERATE----------";
else if(a<=30)
c="----------HOT----------";
else
c="----------TOO HOT----------";
return c;
}

public Temperatureimpl()
{
super();
}
}

Temperatureserver.java

// Comment
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleTemperature.*;
public class Temperatureserver
{
public static void main(String args[])
{
try
{
ORB orb=ORB.init(args,null);
Temperatureimpl temperatureImpl=new Temperatureimpl();
orb. connect(temperatureImpl);
org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
ncRef.rebind(path,temperatureImpl);
System.out.println("Temperature SERVER is Ready");
Thread.currentThread().join();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Temperatureclient.java

// Comment
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleTemperature.*;
public class Temperatureclient
{
public static void main(String args[])
{
try
{
float e=Float.parseFloat(args[2]);
ORB orb=ORB.init(args,null);
NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
NameComponent path[]={new NameComponent("NASDAQ","")};
Temperature tempr=TemperatureHelper.narrow(ncRef.resolve(path));
System.out.println("\t\t Weather Casting");
System.out.println("\t\t_ _ _ _ _ _ _ _ _ _ _ _");
System.out.println("Input is:"+e);
System.out.println("WEATHER is:"+tempr.get_tmp(e));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Output Screen
raja P Web Developer

Download Files From Various Servers Using RMI


To Create  a program to download files from various servers using RMI

  •   Define the interface.
  • Interface must extend Remote
  •   All methods must throw an exception Remote Exception individually
  • Implement the interface.
  •  Create a server program.
  • Create a Client Program.
  •  Generate stubs and skeletons using rmic tool.
  • Start the server.
  •   Start the client.
  • Once the process is over stop the client and server respectively.
fileinterface.java

// Comment
import java.rmi.*;
public interface fileinterface extends Remote
{
public byte[]download file(String s)throws RemoteException;
}

fileimplement.java

// Comment
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
public class fileimplement extends UnicastRemoteObject implements fileinterface
{
private String name;
public fileimplement(String s)throws RemoteException
{
super();
name=s;
}
public byte[]downloadfile(String fn)                                       
{
try
{
File fi=new File(fn);
byte buf[]=new byte[(int)fi.length()];
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn));
bis.read(buf ,0,buf.length);                                                                                                                                                                                                                                            
bis.close();
return(buf);
}
catch(Exception ee)
{
System.out.println("Error:"+ee.getMessage());
ee.printStackTrace();
return(null) ;
}}
}


fileserver.java

// Comment
import java.rmi.*;
import java.io.*;
import java.net.*;
import java.rmi.registry.*;
public class fileserver
{
public static void main(String arg[])
{
try
{
fileimplement fi=new fileimplement("fileserver");
Registry reg=LocateRegistry.createRegistry(5000);
reg.rebind("fileserver",fi);
System.out.println("server is ready");
}
catch(Exception e)
{
System.out.println(" "+e.getMessage());
e.printStackTrace();
}
}
}


fileclient.java

import java.net.*;
import java.rmi.*;
import java.io.*;
public class fileclient
{
    public static void main(String[] args)   
 {
       try{
                //  InetAddress addr=InetAddress.getLocalHost();
          // String address=addr.toString().substring(addr.toString().indexOf("/")+1);
         //  String url="rmi://"+ address + "/fileserver";
           fileinterface f1=(fileinterface)Naming.lookup("rmi://localhost:5000/fileserver");
           byte[] data=f1.downloadfile(args[0]);
           File ff=new File("f1.txt");
           BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ff.getName()));
           bos.write(data,0,data.length);
           bos.flush();
           bos.close();}
           catch(Exception e){
                      System.out.println(" "+e.getMessage());
           e.printStackTrace();           }
}
}
 

Output Screen


 
raja P Web Developer

RemoteMethod Invocation (RMI) using Java


To illustrate the concept of remote control invocation by performing the display message "Hello World"


  • Create a remote interface extending the java.rmi remote interface each remote method interfaces throws a java.rmi remote exception.
  • Define a class that implements that interface of the remote object extending the class java rmi unicust remote object.
  • create a server program that register all remote server objects naming rebind() method is used to bind (ie) to assign name to the remote server object.
  • Compile all the four java file using javac.
  • Run the stub compile (rmic compiler) using command rmic filename.
  • Start rmi registry.
  • Run the server program.
  • Run the client program in seperate command prompt using the command applet viewer filename client java.  
Program


Hello.java

// Comment
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}


HelloImpl.java
// Comment
import java.rmi.*;
import java.rmi.server.*;
public class HelloImpl extends UnicastRemoteObject
implements Hello {
public HelloImpl() throws RemoteException {
}
public String sayHello() throws RemoteException{
return "Hello World!";
}
}


Helloserver.java

// Comment
import java.rmi.*;
import java.rmi.registry.*;
public class Helloserver
{
public static void main(String args[]) {
try {
HelloImpl obj=new HelloImpl();
Registry reg=LocateRegistry.createRegistry(5000);
reg.rebind("Helloserver",obj);
System.out.println("Server Starts........");
String ab[]=reg.list();
System.out.println("The Remote Object Available Are:");
for(int i=0;i<ab.length;i++)
System.out.println(ab[i]);
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}


Helloclient.java

// Comment
import java.rmi.*;
public class Helloclient
{
public static void main(String args[])
{
String str="";
Hello obj=null;
try {
obj=(Hello)Naming.lookup("rmi://localhost:5000/Helloserver");
System.out.println(str);
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
}
Ouput Window 

raja P Web Developer

Related Posts Plugin for WordPress, Blogger...