Archive for August, 2009

22
Aug
09

BlazeDs – HelloWorld Example

BlazeDS is a server-based Java remoting technology that allows you to connect to back-end distributed data and push data in real-time to Adobe Flex and Adobe AIR rich Internet applications (RIA).

You can get more information on BlazeDs on the following link “http://livedocs.adobe.com/blazeds/1/blazeds_devguide/”>

Below Are the steps to configure and run a Sample Program Using BlazeDS

Requirement:

Apache-tomcat-6.0.18 (download zip (pgp, md5) )

FlexBuilder

Step1:
Create a folder named BlazeDs in ${Tomcat}/webapps

Step2:
Download the BlazeDS Binaries from the following link
Download the BlazeDS binary distribution and extract it to ${Tomcat}/webapps/BlazeDs

step3:
Create a java Program “HelloWorld.java” in ${tomcat}\webapps\BlazeDs\WEB-INF\classes location

public class HelloWorld

{
public HelloWorld(){}
public String sayHello()
{
return “Hello World. It’s Working”;
}
}
compile and create the class file in the same location

step4:

Add the Following node in ${tomcat}\webapps\BlazeDs\WEB-INF\flex\remoting-config.xml

<service id=”remoting-service”  class=”flex.messaging.services.RemotingService”>
. . .
. . .

<destination id=”HelloWorld”>
<properties>
<source>HelloWorld</source>
</properties>
</destination>

. . .
. . .

</service>

Step5:
Create a new Project(name “BlazeDS”) using Flex Builder.

Copy and Paste the below code in BlazeDs.mxml

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”horizontal” >
<mx:RemoteObject id=”ro” destination=”HelloWorld” result=”resultHandler(event)” fault=”faultHandler(event)”/>
<mx:Panel x=”10″ y=”10″ width=”604″ height=”643″ layout=”absolute” backgroundColor=”#DFE8EC” cornerRadius=”6″ alpha=”1.0″ backgroundAlpha=”0.52″ borderStyle=”inset” fontWeight=”bold” themeColor=”#1611EF” color=”#1B3DE8″>
<mx:TextArea id=”text” text=”initial text” x=”240″ y=”61″ width=”273″ height=”56″/>
<mx:Text x=”62″ y=”10″ text=”Blaze DS Example” width=”431″ height=”28″ fontFamily=”Georgia” fontSize=”15″ alpha=”0.58″ color=”#389AAF” textAlign=”center” fontWeight=”bold” fontStyle=”italic”/>
<mx:Button x=”244″ y=”152″ label=”Click Me” fontStyle=”italic” themeColor=”#0B0BF6″ borderColor=”#291AE6″ click=”ro.sayHello()” />
<mx:Label x=”32″ y=”62″ text=”Data Returned from the server ” width=”189″ color=”#5BA9BA”/>
<mx:Button x=”338″ y=”152″ label=”Reset” fontStyle=”italic” themeColor=”#0B0BF6″ borderColor=”#291AE6″ click=”reset()”  width=”62″/>
</mx:Panel>

<mx:Script>
<![CDATA[

import mx.controls.Alert;

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.utils.ObjectUtil;

import mx.utils.StringUtil;

var str:String

private function resultHandler(event:ResultEvent):void

{

text.text= ObjectUtil.toString(event.result)

}

private function faultHandler(event:FaultEvent):void

{

Alert.show( ObjectUtil.toString(event.fault) );

}

public function reset():void{

text.text="initial text";

}

]]>
</mx:Script>

</mx:Application>

set the Additional compiler arguments for Flex Compiler

-services ${tomcat}\webapps\BlazeDS\WEB-INF\flex\services-config.xml -context-root /BlazeDs

Clean and build the Project again

now copy and paste the generated output files BlazeDS.html , BlazeDS.swf and AC_OETags files to ${tomcat}\webapps\BlazeDS\

Step6:

Stop and Start your tomcat server

Hit The Following URL

http://localhost:8080/BlazeDs/BlazeDS.swf  (or)

http://localhost:8080/BlazeDs/BlazeDS.html

output

21
Aug
09

JAVA PhoneBook Application

It Is a Simple Java Phone Book Application Created Using Eclipse IDE. In this the data are stored in the File System in the form of Objects. Below are the Steps to create and run the Application

Step 1 : Create a New Java Procject Named phoneBookApp in Eclipse. and then Create a new class phoneBook(java file) Click Finish

Step2 : Create a file store.dat in D:/data/workspace/phoneBook/ Path Copy and Paste the below Prog in the “phoneBook. java” File

 

 

import java .io .*;

import java .util .*;

 

public class phoneBook

{

             public static void main  (String[] args)

     {

     phoneBook cl=new phoneBook();

     BufferedReader br;

     String ch=”";

     try

         {  

            System.out.println(“Phone Book Application Using JAVA prog”);

         do

            {

                                    cl.menu();

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

                                    System.out.print(“Enter your option      :”);

                                    ch=br.readLine();

                                    if (ch.equals(“1″))

                                        cl.new_record();

                                    if (ch.equals(“2″))

                                        cl.display_record();

                                    if (ch.equals(“3″))

                                        cl.display_by_name();

                                    if (ch.equals(“4″))

                                        cl.display_by_city();

                                    if (ch.equals(“5″))

                                        cl.display_record_first_letter();

                                    if (ch.equals(“6″))

                                        cl.replace_record();

                                    if (ch.equals(“7″))

                                        cl.delete_record();

                                    if (ch.equals(“8″))

                                                System.out.println(“Thanks”);

            } while(!ch.equals(“8″));

 

         }

         catch(Exception E){}

     }

           

           

           

    public void new_record()

    {

       String id,name,city,add,number,total;

         boolean bln=false;

              try

        {

          Properties pr=new Properties();

          FileInputStream fin=new FileInputStream(“D:/data/workspace/phoneBook/store.dat”);

           if(fin!=null)

             {

             pr.load(fin);

             }   

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

              FileOutputStream fout=new  FileOutputStream(“store.dat”);

                  for(;;)

                   {

                     System.out .println(“Enter the ‘ID’, ‘q’ for quit:”);

                     id=br1.readLine().toUpperCase();

                     bln=pr.containsKey(id);

                     if(bln)

                      {

                       System.out.println(“ID id already exists, Please Enter another ID:”);

                       continue;

                      }

                    if((id.toUpperCase()).equals(“Q”))

                    break;

                    System.out.println(“Enter name:”);

              name=br1.readLine().toUpperCase();

              System.out.println(“Enter Phone number:”);

              number=br1.readLine().toUpperCase();

                System.out.println(“Enter address:”);

              add=br1.readLine().toUpperCase();

              System.out.println(“Enter city:”);

              city=br1.readLine().toUpperCase();

              total=”    Name=”+name+”,”+”Phone no=”+number+”,”+” Address=”+add+”,”+”    City=”+city;

                    total=total.toUpperCase();

              pr.put(id,total);

              pr.store(fout,”My Telephone Book”);

                 }

              fout.close();

        }

          catch(Exception e)

          {

                System.out.println(e);

          }

    }   

           

    public void display_record()

    {

        String;

        String total=”";

                int x=1;

        try

        {

            FileInputStream fin=new FileInputStream(“store.dat”);

            Properties pr1=new Properties();

            pr1.load(fin);

            Enumeration enum1=pr1.keys();

            while(enum1.hasMoreElements())

            {

              id=enum1.nextElement().toString();

              total=pr1.get(id).toString();

              StringTokenizer stk=new StringTokenizer(total,”=,”);

                          System.out .println(“RECORD ::”+x+”\n”);

                          x++;

              while(stk.hasMoreTokens())

              {

                  String key=stk.nextToken();

                  String value=stk.nextToken();

                  System.out.println(“\t”+key+”::\t\t::”+value);

                                   try

                                     {

                                       Thread.sleep(1000);

                                     }

                                      catch(Exception e){}

              }

                          System.out.println(“”);

                          System.out.println(“”);

            }

             fin.close();

        }

        catch(Exception e){}

    }

         public void display_by_name()

          {

            String,id,total;

            String key[]=new String[4];

            String value[]=new String[4];

            int i=0;

           

        System.out.println(“Enter Name For Searching Record :-”);

        try

        {

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

                  name=br.readLine().toUpperCase();

                  FileInputStream fin=new FileInputStream(“store.dat”);

            Properties pr1=new Properties();

            pr1.load(fin);

            Enumeration enum1=pr1.keys();

            while(enum1.hasMoreElements())

            {

              id=enum1.nextElement().toString();

              total=pr1.get(id).toString();

              StringTokenizer stk=new StringTokenizer(total,”=,”);

             

                     while(stk.hasMoreTokens())

              {

                 

                         for(i=0;i<4;i++)

                         {

                           key[i]=stk.nextToken();

                           value[i]=stk.nextToken();

                         }

                           if(value[0].equals(name))

                            {

                              for(i=0;i<4;i++)

                               {

                                 System.out.println(“\t”+key[i]+”:”+value[i]);

                                try

                                     {

                                       Thread.sleep(1500);

                                     }

                                      catch(Exception e){}

                               }                             

 

 

                            }

              }

                      System.out.println(“”);

                         

                       

            }

             fin.close();

        }

        catch(Exception e){

            System.out.println(e);

            }

}   

       

public void display_by_city()

{

    String city=”",id,total;

    String key2[]=new String[4];

    String value2[]=new String[4];

    int i=0;

 

             System.out.println(“Enter City For Searching Record :-”);

          try

        {

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

                  city=br.readLine().toUpperCase();

                  FileInputStream fin=new FileInputStream(“store.dat”);

            Properties pr1=new Properties();

            pr1.load(fin);

            Enumeration enum1=pr1.keys();

            while(enum1.hasMoreElements())

            {

              id=enum1.nextElement().toString();

              total=pr1.get(id).toString();

              StringTokenizer stk=new StringTokenizer(total,”=,”);

                   

              while(stk.hasMoreTokens())

              {

                   key2[i]=stk.nextToken();

                           value2[i]=stk.nextToken();

                         // System.out.println(“aaaaaaaaaaaaaaa”+value2[i]);

                         if(i==3)

                          {

                           if(value2[i].equals(city))

                            {

                              for(int j=0;j<4;j++)

                               {

                                 System.out.println(“\t”+key2[j]+”:\t”+value2[j]);

                                 try

                                     {

                                       Thread.sleep(1500);

                                     }

                                      catch(Exception e){}

                               

                               }   

                            }

                          }

                         i++;

                         if(i>3)

                           i=0;

              }

                          System.out.println(“”);

                          System.out.println(“”);

            }

             fin.close();

        }

        catch(Exception e){

            System.out.println(e);

            }

 

 

   }

 

public void display_record_first_letter()

{

 

    String,id,total,str=”";

    String key2[]=new String[4];

    String[] value2=new String[4]; 

    int i=0;

           

       

        try

        {

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

                  System.out.println(“        Enter The First Letter Of any Name:”);

                  name=br.readLine();

                  name=name.substring(0,1).toUpperCase();

                  FileInputStream fin=new FileInputStream(“store.dat”);

            Properties pr1=new Properties();

            pr1.load(fin);

            Enumeration enum1=pr1.keys();

            while(enum1.hasMoreElements())

            {

              id=enum1.nextElement().toString();

              total=pr1.get(id).toString();

              StringTokenizer stk=new StringTokenizer(total,”=,”);

             

                     while(stk.hasMoreTokens())

              {

                 

                           for(i=0;i<4;i++)

                           {

                           key2[i]=stk.nextToken();

                           value2[i]=stk.nextToken();

                          }

                          str=value2[0].substring(0,1);

                         

                           if(str.equals(name))

                            {

                             for(i=0;i<4;i++)

                              {

                                System.out.println(“\t”+key2[i]+”:\t”+value2[i]); 

                                try

                                     {

                                       Thread.sleep(1500);

                                     }

                                      catch(Exception e){}

                            }

                          }

                         

              }

                          System.out.println(“”);

                          System.out.println(“”);

 

                         

                       

            }

             fin.close();

        }

        catch(Exception e){

            System.out.println(e);

            }

}

     public void replace_record()

      {

           String id,name,city,add,number,total,list;

         boolean bln=false;

              try

        {

          Properties pr=new Properties();

          FileInputStream fin=new FileInputStream(“store.dat”);

           if(fin!=null)

             {

             pr.load(fin);

             }   

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

              FileOutputStream fout=new  FileOutputStream(“store.dat”);

                  for(;;)

                   {

                     System.out .println(“Enter the ‘ID’, ‘q’ for quit:”);

               id=br1.readLine().toUpperCase();

                     if((id.toUpperCase()).equals(“Q”))

                    break;

                   

                     bln=pr.containsKey(id);

                     if(bln)

                      {

                       System.out.println(“ID id already exists, “);

                      

                     

                    System.out.println(“enter name:”);

              name=br1.readLine().toUpperCase();

              System.out.println(“enter Phone number:”);

              number=br1.readLine().toUpperCase();

                System.out.println(“enter address:”);

              add=br1.readLine().toUpperCase();

              System.out.println(“enter city:”);

              city=br1.readLine().toUpperCase();

              total=”    Name=”+name+”,”+”Phone no=”+number+”,”+” Address=”+add+”,”+”    City=”+city;

                    total=total.toUpperCase();

              pr.put(id,total);

              pr.store(fout,”My Telephone Book”);

                 }

                    else

                         {

                           System.out.println(“ID does’nt Exists, Please Enter A Valid ID:”);

                           continue;

                         }

                       

               }

             pr.store(fout,”My Phone Book”);

                   fout.close();

        }

          catch(Exception e)

          {

                System.out.println(e);

          }

    }   

   public void delete_record()

   {

     

   String;

         boolean bln=false;

              try

        {

          Properties pr1=new Properties();

          FileInputStream fin=new FileInputStream(“store.dat”);

          if(fin!=null)

            pr1.load(fin);

                

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

              FileOutputStream fout=new  FileOutputStream(“store.dat”);

                  for(;;)

                   {

                     System.out .println(“Enter the ‘ID’, ‘q’ for quit:”);

               id=br1.readLine().toUpperCase();

                     if((id.toUpperCase()).equals(“Q”))

                     

                       

                        break;

                   

                     bln=pr1.containsKey(id);

                   

                     if(bln)

                      {

                       System.out.println(“ID  exists :”);

                       String str=pr1.remove(id).toString();

                       pr1.store(fout,”My Phone Book”);

                       try

                                     {

                                       Thread.sleep(1000);

                                     }

                                      catch(Exception e){} 

                      System.out.println(“Record deleted successfully”);

                      }

                        else

                         {

                           System.out.println(“Enter Existing ID:”);

                            pr1.store(fout,”My Phone Book”); 

                         }

                     

                  }

              pr1.store(fout,”My Phone Book”);

                    fin.close();

                    fout.close();

        }

          catch(Exception e)

          {

                System.out.println(e);

          }

    }   

           

   

 

             

public void menu()

           {

        char ch=30;

            char ch1=31;

            int l;

            for(int i=0;i<27;i++)

            {

              System.out.print(” “);

            }

            for(l=0;l<2;l++)

           {

           

            for(int j=0;j<38;j++)

            {

           

              System.out.print(ch);

            }

              System.out.println(“”);

               for(int k=0;k<27;k++)

            {

              System.out.print(” “);

            }

          }

            System.out.print(ch); 

            System.out.print(ch1);

            for(int i=0;i<34;i++)

            System.out.print(” “);

            System.out.print(ch);

            System.out.print(ch1);

            System.out.println(“”);

            for(int i=0;i<27;i++)

            System.out.print(” “);

           

            System.out.print(ch);

            System.out.print(ch1+” “);

            System.out.print (” 1. Enter new Record:           “);

           

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch1);

            System.out.print(ch+” “);

           

           

        System.out.print (” 2. Display All Record:         “);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

             

           

        System.out.print (” 3. Search Record by name:      “);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

           

        System.out.print (” 4. Search Record by city:      “);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

           

           

        System.out.print (” 5. Search Record by 1st letter:”);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

           

           

            System.out .print(” 6. Replace Record:             “);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

           

           

        System.out .print(” 7. Delete Record:              “);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

           

            for(int i=0;i<26;i++)

            System.out.print(” “);

            System.out.print(” “+ch);

            System.out.print(ch1+” “);

           

           

        System.out .print(” 8. Exit:                       ”);

            System.out.print(” “+ch);

            System.out.println(ch1+” “);

           

 

            for(int j=0;j<27;j++)

            System.out.print(” “);

            System.out.print(ch); 

            System.out.print(ch1);

            for(int i=0;i<34;i++)

            System.out.print(” “);

            System.out.print(ch);

            System.out.print(ch1);

            System.out.println(“”);

            for(int i=0;i<27;i++)

            System.out.print(” “);

            for(int i=0;i<38;i++)

            System.out.print(ch);

            System.out.println(“”);

            for(int i=0;i<27;i++)

            System.out.print(” “);

            for(int i=0;i<38;i++)

            System.out.print(ch);

                   

           }   

 

       

            }

 

OUTPUT :

 

Phone Book Application Using JAVA prog

                            1. Enter new Record:            

                            2. Display All Record:          

                            3. Search Record by name:       

                            4. Search Record by city:       

                            5. Search Record by 1st letter: 

                            6. Replace Record:             

                            7. Delete Record:              

                            8. Exit:                       

                           Enter your option      :1

                          

Enter the ‘ID’, ‘q’ for quit:

123

enter name:

gopu

enter Phone number:

12345

enter address:

abc

enter city:

chennai

Enter the ‘ID’, ‘q’ for quit:

q

Notify me of follow-up comments via email.

21
Aug
09

Java – Hello World

First Java Program

First to Compile and run a java program you need a Java SE Development Kit . if you don’t have java SE Development Kit download and install from the above link

Below are the steps to compile and  run a java Program

Step1.

create a folder JavaProg. I have Created in D:\data\JavaProg

Step2.

Open a text file copy and paste the helloWorld program and save it as “helloWorld.java” in D:\data\JavaProg

public class helloWorld

{

public static void main(String[] args)

{

System.out.println(“Hello World”);

}

}

Step3.

Open a command Promt and type the following commands

java execution

Commands are highlighted by a red box and output was highlighted by a green box..
Notify me of follow-up comments via email.




Follow

Get every new post delivered to your Inbox.