Java Tutorial

 
 
 
 
// encrypt.idl

module encrypt_val
{
  interface encrypt
  {
    string getstr(in string a);
  };
};


// encrypt_client.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.*;
public class encrypt_client
{
    static encrypt encryptimpl;
    public static void main(String args[])
    {
      try
      {

        String result_str,tempstr;
        ORB orb=ORB.init(args,null);
        org.omg.CORBA.Object objref=orb.resolve_initial_references(\"NameService\");

        NamingContextExt ncref=NamingContextExtHelper.narrow(objref);

        String pathname=\"encrypt\";
        encryptimpl=encryptHelper.narrow(ncref.resolve_str(pathname));

        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        System.out.println(\"Enter string you want to send to server : \");
        tempstr=in.readLine();
        StringBuffer string1=new StringBuffer(tempstr);
    for(int i=0;i<string1.length();i++)
        {
          string1.setCharAt(i,(char)(string1.charAt(i)+2));
        }
        System.out.println(\"Encrypted string sent to server : \"+string1);

        result_str=encryptimpl.getstr(string1.toString());

        System.out.println(\"Decrypted string recvd from server is as below:\");
        System.out.println(result_str);

      }
      catch(Exception e)
      {
         System.out.println(e);
      }
    }

}


// encrypt_server.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.lang.*;
import java.util.*;
import java.text.*;
class serverimpl extends encryptPOA
{
   private ORB orb;
   public void setorb(ORB orb_val)
   {
      orb=orb_val;
   }

   public String getstr(String str1)
   {
     StringBuffer strb1=new StringBuffer(str1);
     Date dateobj=new Date();
     SimpleDateFormat sdf;
     sdf=new SimpleDateFormat(\"hh:mm:ss\");

     String datestr=sdf.format(dateobj).toString();
     datestr=\" \"+datestr+\" \";

     for(int i=0;i<strb1.length();i++)
        {
          strb1.setCharAt(i,(char)(strb1.charAt(i)-2));
          if(strb1.charAt(i)==\' \')
            {
             strb1.insert(i,datestr);
             i=i+datestr.length();
            }
       }
     return(strb1.toString());
   }
}
public class encrypt_server
{
   public static void main(String args[])
   {
     try
     {
         ORB orb=ORB.init(args,null);

         org.omg.CORBA.Object objref1=orb.resolve_initial_references(\"RootPOA\");
         POA rootpoa=POAHelper.narrow(objref1);
         rootpoa.the_POAManager().activate();

         serverimpl serverobj=new serverimpl();
         serverobj.setorb(orb);
         org.omg.CORBA.Object objref2=rootpoa.servant_to_reference(serverobj);
         encrypt href=encryptHelper.narrow(objref2);

         org.omg.CORBA.Object objref3= orb.resolve_initial_references(\"NameService\");
         NamingContextExt ncref=NamingContextExtHelper.narrow(objref3);
         String pathname=\"encrypt\";
         NameComponent path[]=ncref.to_name(pathname);
         ncref.rebind(path,href);


         System.out.println(\"server ready and waiting...\");

         orb.run();

     }
     catch(Exception e)
     {
       System.out.println(e);
     }
   }


}


// Output :

E:\\DIPI1\\corba prgs\\encrypt>java encrypt_client -ORBInitialPort 1050 -ORBInitialHost a

Enter string you want to send to server :
hi how are you
Encrypted string sent to server : jk\"jqy\"ctg\"{qw
Decrypted string recvd from server is as below:
hi 07:15:56  how 07:15:56  are 07:15:56  you

    Related Post:
  1. Application for counting factorial of a given number

  2. Corba program of game

  3. Program to show the use of Bitwise Operator (~) Complement

  4. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  5. Program to show an example of Concatination of Strings

  6. Program to copy the elements of an array into another array in reverse order and print them

  7. An applet program to display Horizontal Color Bar

  8. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  9. RMI servlet program to display message

  10. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  11. Program of binary search tree

  12. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  13. Program to show an example of searching Strings for characters

  14. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  15. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  16. Program to read the table elements into a two-dimensional array temperature

  17. Program to show some properties of StringBuffer object

  18. Servlet which takes input from an HTML client page and calculates and outputs the premium amount

  19. An applet program showing Clicked Event on canvas

  20. Program to show an example of creating a class and using its object