Sunday, October 16, 2011

JAVA J2EE


Enterprise programming ppt's


                     Hi, Now i am posting the PPT's for the ENTERPRISE PROGRAMMING subject of ANU (NAGARJUNA UNIVERSITY). Which broadly covers the concepts of  J2EE Web Services: XML SOAP WSDL UDDI WS-I JAX-RPC JAXR OF COURSE JAVAEE. The topics covered in this ppt's are described below

UNIT-1

J2EE INTRODUCTION, JAX (JAVA API FOR XML) INCLUDES DOM AND SAX PARSERS

UNIT-2

JAVA SERVLETS, JSP'S (JAVA SERVER PAGES) AND EJB'S (SESSION AND ENTITY)

UNIT-3

JAVA MAIL API, JAVA MESSAGE SYSTEM (JMS), JNDI(JAVA NAMING AND DIRECTORY INTERFACE)

UNIT-4

SOAP (SIMPLE OBJECT ACCESS PROTOCOL)
UDDI ( UNIVERSAL DESCRIPTION, DISCOVERY AND INTEGRATION)
EBXML (ELECTRONIC BUSINESS XML)
JAXR (JAVA API FOR XML REGISTRIES )
WSDL (WEB SERVICES DESCRIPTION LANGUAGE )


TO DOWNLOAD THIS PPTS I AM PROVIDING TWO DOWNLOADING RESOURCES ziddu.com and mediafire.com


IN ZIDDU.COM

UNIT-1

http://www.ziddu.com/download/11836008/j2ee_intro.ppt.html

http://www.ziddu.com/download/11836023/J2eeIntro.ppt.html

http://www.ziddu.com/download/11836027/XMLProcessing.ppt.html

http://www.ziddu.com/download/11836032/xml-parsing.ppt.html


UNIT-2


http://www.ziddu.com/download/11836063/Servlets.ppt.html

http://www.ziddu.com/download/11836067/jsp_presentation.ppt.html

http://www.ziddu.com/download/11836069/Introduction To EJB.ppt.html


UNIT-3


http://www.ziddu.com/download/11836081/jms.ppt.html

http://www.ziddu.com/download/11836084/JAVA MESSAGE SERVICE 03.ppt.html

http://www.ziddu.com/download/11836086/javamail.ppt.html

http://www.ziddu.com/download/11836089/java mail api raj.ppt.html

http://www.ziddu.com/download/11836093/jndi 03.ppt.html


UNIT-4

http://www.ziddu.com/download/11836119/SOAP 03.ppt.html

http://www.ziddu.com/download/11836120/UDDI 03.ppt.html
 
http://www.ziddu.com/download/11836114/EB-XML03.ppt.html

http://www.ziddu.com/download/11836105/JAXR 03.ppt.html

http://www.ziddu.com/download/11836121/WSDL 03.ppt.html

IF YOU WANT TO DOWNLOAD ALL AT ONE LINK:
http://www.ziddu.com/download/11836913/EP_MATERIALS_PPTS.rar.html


IN MEDIAFIRE.COM

UNIT-1

http://www.mediafire.com/file/chyno4bmvly5zdr/j2ee_intro.ppt

http://www.mediafire.com/file/f58pj12yzpz48xz/J2eeIntro.ppt

http://www.mediafire.com/file/shibn7gdejjj6ln/xml-parsing.ppt

http://www.mediafire.com/file/4dgoir5x95zinba/XMLProcessing.ppt


UNIT-2

http://www.mediafire.com/file/sj12q9n6s492w77/Servlets.ppt

http://www.mediafire.com/file/4gme995bd4tpl6u/jsp_presentation.ppt

http://www.mediafire.com/file/7q4x3g4v2b2nxva/Introduction%20To%20%20EJB.ppt

UNIT-3

http://www.mediafire.com/file/j5duaz7yi2czpyo/java%20mail%20api%20raj.ppt

http://www.mediafire.com/file/yv7ywobf4tbtv6o/JAVA%20MESSAGE%20SERVICE%2003.ppt

http://www.mediafire.com/file/8tzz9mhw6pzccjz/javamail.ppt

http://www.mediafire.com/file/gj37cl07gm34gx8/jndi%2003.ppt

http://www.mediafire.com/file/85azkw5oo10qzfv/jms.ppt


UNIT-4

http://www.mediafire.com/file/c7d8h3hrnv437nb/SOAP%2003.ppt

http://www.mediafire.com/file/of80hqh4289tz36/UDDI%2003.ppt

http://www.mediafire.com/file/h5h9xuifh447nnt/EB-XML03.ppt

http://www.mediafire.com/file/ac8u9cg6t0y4b2r/JAXR%2003.ppt

http://www.mediafire.com/file/3in5rimsddd2mh3/WSDL%2003.ppt


IF YOU WANT TO DOWNLOAD ALL AT ONE LINK:
http://www.mediafire.com/file/mbjh9p1w215r9sa/EP_MATERIALS_PPTS.rar



AND I WILL GIVE MORE JAVA RESOURCES SOON, ANY QUERY POST IN COMMENTS OF THIS POST
Head First Java, 2nd Edition

An application that access CORBA service using J IDL



Aim: Write an CORBA application using JAVA IDL
Required programs:
  • IDL file(interface) for simple HelloWorld
  • A Server class
  • A Client class
Hello.idl
module HelloApp
{
  interface Hello
  {
  string sayHello();
  oneway void shutdown();
  };
};
Implementing the Server (HelloServer.java)
HelloServer.java

import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

import java.util.Properties;

class HelloImpl extends HelloPOA{
  private ORB orb;

  public void setORB(ORB orb_val){
    orb = orb_val;
  }
 
  public String sayHello(){
    return "\nHello world !!\n";
  }
 
  public void shutdown(){
    orb.shutdown(false);
  }
}

public class HelloServer{

  public static void main(String args[]){
    try{
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      // Get reference to rootpoa & activate the POAManager
      POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
      rootpoa.the_POAManager().activate();

      // create servant and register it with the ORB
      HelloImpl helloImpl = new HelloImpl();
      helloImpl.setORB(orb);

      // create a tie, with servant being the delegate.
      HelloPOATie tie = new HelloPOATie(helloImpl, rootpoa);

      // obtain the objectRef for the tie
      // this step also implicitly activates the
      // the object
      Hello href = tie._this(orb);
           
      // get the root naming context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
     
      // Use NamingContextExt which is part of the Interoperable
      // Naming Service specification.
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // bind the Object Reference in Naming
      String name = "Hello";
      NameComponent path[] = ncRef.to_name( name );
      ncRef.rebind(path, href);

      System.out.println("HelloServer ready and waiting ...");

      // wait for invocations from clients
      orb.run();
      }
     
    catch (Exception e){
      System.err.println("ERROR: " + e);
      e.printStackTrace(System.out);
    }
   
    System.out.println("HelloServer Exiting ...");
       
  }
}

HelloClient.java


import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;

public class HelloClient{

  public static void main(String args[]){
 
    try{
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      // get the root naming context
      org.omg.CORBA.Object objRef =
          orb.resolve_initial_references("NameService");
         
      // Use NamingContextExt instead of NamingContext. This is
      // part of the Interoperable naming Service. 
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // resolve the Object Reference in Naming
      String name = "Hello";
      Hello helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));

      System.out.println("Obtained a handle on server object: " + helloImpl);
      System.out.println(helloImpl.sayHello());
      helloImpl.shutdown();
      }
     
    catch (Exception e) {
      System.out.println("ERROR : " + e) ;
      e.printStackTrace(System.out);
    }
  }
}






To run this client-server application on your development machine:
  1. Change to the directory that contains the file Hello.idl.
  2. Run the IDL-to-Java compiler, idljtwice on the IDL file to create stubs and skeletons. This step assumes that you have included the path to the java/bin directory in your path.
3.    idlj -fall  Hello.idl
4.    idlj -fallTie Hello.idl
    • It generates

    • HelloPOA.java
    • _HelloStub.java
    • Hello.java
    • HelloHelper.java
    • HelloHolder.java
    • HelloOperations.java

  1. Compile the .java files, including the stubs and skeletons (which are in the directoryHelloApp). This step assumes the java/bin directory is included in your path.

6.     javac *.java HelloApp/*.java

  1. Start orbd.
  start orbd -ORBInitialPort 1050 -ORBInitialHost localhost
  1. Start the Hello server.
start java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost
  1. Run the client application:
 java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost

output:

Obtained a handle on server object: IOR:000000000000001749444c3a48656c6c6f417070
2f48656c6c6f3a312e300000000000010000000000000082000102000000000a3132372e302e302e
3100055a00000031afabcb00000000203a12163f00000001000000000000000100000008526f6f74
504f4100000000080000000100000000140000000000000200000001000000200000000000010001
00000002050100010001002000010109000000010001010000000026000000020002

Hello world !!


A Program for Demonstrating JNDI (JAVAEE) using GLASSFISH



Aim: Write a program to demonstrate JNDI

program:

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
class MyLookupClass {
  public static void main(String[] args) {
    String myObject = " ";            // use your obj name
    Hashtable ep = new Hashtable(1);
    ep.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.fscontext.RefFSContextFactory");
    try {
      InitialContext ct = new InitialContext(ep);
Object obj = ct.lookup(myObject);
System.out.println("Object: " + obj);
 ct.close();
    }
    catch (NamingException error) {
      System.err.println("Error:" + error.getMessage());
    }
  }
}


Execution steps:

step 1:
set the classpaths before the compilation and run.Here GLASSFISH is the Application server

a)set the foldername where we are executing the jndi
b)set the fscontext.jar
c)set the javaee.jar
d)set the jndi-properties.jar

step 2:

compile the code using "javac"
javac MyLookupClass.java

step 3:

Run the code using "java" at cmd prompt

java MyLookupClass

output:(Appears on the same cmd prompt)

Object: com.sun.jndi.fscontext.RefFSContext@1050e1f

A Program for Sending mail in java (JAVAEE)



Aim: Write a program to demonstrate java mail

program:

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class javamail_send extends Object {

  public static void main(String args[]){

    String smtpServer = null;
    String toEmail    = null;
    String fromEmail  = null;
    String body       = null;
  
    //--[ Parse the Command line parameters
    for ( int x=0; x < args.length-1; x++ ){
      if ( args[x].equalsIgnoreCase("-S") )
        smtpServer  = args[x+1];
      else if ( args[x].equalsIgnoreCase("-T") )
        toEmail     = args[x+1];
      if ( args[x].equalsIgnoreCase("-F") )
        fromEmail  = args[x+1];
      if ( args[x].equalsIgnoreCase("-B") )
        body  = args[x+1];
    }
  
  if ( smtpServer == null || toEmail == null || fromEmail == null || body == null ){
    System.out.println( "Usage: javamail_send -S -T -F -B " );
    System.exit(1);
  }

  //--[ Obtain a session
  try{
    //--[ Set up the default parameters
      Properties props = new Properties();
      props.put("mail.transport.protocol", "smtp" );
      props.put("mail.host", smtpServer );              
  

     //--[ Create the session and create a new mail message
      Session mailSession = Session.getInstance( props );
      Message msg = new MimeMessage( mailSession );

    //--[ Set the FROM, TO, DATE and SUBJECT fields
      msg.setFrom( new InternetAddress( fromEmail ) );
      msg.setRecipients( Message.RecipientType.TO,
                         InternetAddress.parse(toEmail) );
      msg.setSentDate( new Date() );
      msg.setSubject( "Test Mail" );

      //--[ Create the body of the mail
      msg.setText( body );

      Transport.send( msg );
    
      System.out.println( "The email below was sent successfully" );
      msg.writeTo( System.out );

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



Execution Procedure:

step 1:  save this code with javamail_send.java and compile the code using javac.

  i.e.
  c:\>cd javamail  //this enters into the javamail folder
  c:\javamail> javac javamail_send.java

step 2: Set the classpath

  it can be done with the help of classpath setting in the environmental varialbles( taking GLASSFISH as app server )

 a) set the javaee.jar
 b) set the mail.jar
 c) the folder name where we are compiling our code
 d)make sure smtp server should be in our system(windows providing default smtp server as a optional component)

step 3: Run the code

c:\javamail>java javamail_send -s localhost -t localhost -f localhost -b "Hai, this is the program for jmail"

output:

The email below was sent successfully
Date: Wed, 22 Sep 2010 20:52:59 +0530 (IST)
From: localhost
To: localhost
Message-ID: <10748354.0.1285168979984.JavaMail.maxx@localhost>
Subject: Test Mail
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



//AUTHOR---MIS

                       HI, THIS POST SHOWS EACH AND EVERY STEP FOR THE EXECUTION OF A RMI PROGRAM WITH APPROPRIATE SCREEN SHOTS.

HERE I AM CONSIDERING A CALCULATOR EXAMPLE.

Basically we need four java files for this execution process:
1) Calculator Interface             :Calculator.java
2)Calculator Implementation    :CalculatorImpl.java
3)Calculator  Server                :CalculatorServer.java
4)Calculator Client                  :CalculatorClient.java

Programs for calculator operation:

//file name is: Calculator.java

public interface Calculator extends java.rmi.Remote {
    public long add(long a, long b)
        throws java.rmi.RemoteException;

    public long sub(long a, long b)
        throws java.rmi.RemoteException;

    public long mul(long a, long b)
        throws java.rmi.RemoteException;

    public long div(long a, long b)
        throws java.rmi.RemoteException;
}
 

//2.file name is: CalculatorImpl.java

import java.rmi.*;
import javax.rmi.*;
public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject implements Calculator {

    // Implementations must have an 
    //explicit constructor
    // in order to declare the 
    //RemoteException exception
    public CalculatorImpl()
        throws java.rmi.RemoteException {
        super();
    }

    public long add(long a, long b)
        throws java.rmi.RemoteException {
        return a + b;
    }

    public long sub(long a, long b)
        throws java.rmi.RemoteException {
        return a - b;
    }

    public long mul(long a, long b)
        throws java.rmi.RemoteException {
        return a * b;
    }

    public long div(long a, long b)
        throws java.rmi.RemoteException {
        return a / b;
    }
}



//3.filename is:CalculatorServer.java


import java.rmi.Naming;

public class CalculatorServer {

  public CalculatorServer() {
    try {
      Calculator c = new CalculatorImpl();
      Naming.rebind("rmi://localhost:1099/CalculatorService", c);
    } 
catch (Exception e) {
      System.out.println("Trouble: " + e);
    }
  }

  public static void main(String args[]) {
    new CalculatorServer();
  }
}



//4.file name is:CalculatorClient.java


import java.rmi.Naming;
import java.rmi.RemoteException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;

public class CalculatorClient {

    public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        try {
            Calculator c = (Calculator)Naming.lookup("rmi://localhost/CalculatorService");
            //System.out.println( c.sub(4, 3) );
            //System.out.println( c.add(4, 5) );
            //System.out.println( c.mul(3, 6) );
            //System.out.println( c.div(9, 3) );
            System.out.println("1-add 2-sub 3-mul 4-div");
            System.out.println("ENTER YOUR CHOICE:");
            int x=Integer.parseInt(br.readLine());
            switch(x)
            {
            case 1:
                System.out.println("enter two numbers:");
                int y=Integer.parseInt(br.readLine());
                int z=Integer.parseInt(br.readLine());
                System.out.println(c.add(y,z));
                  break;
            case 2:
                System.out.println("enter two numbers:");
                 y=Integer.parseInt(br.readLine());
                 z=Integer.parseInt(br.readLine());
                System.out.println(c.sub(y,z));
                 break;
              case 3:
                   {
                System.out.println("enter two numbers:");
                 y=Integer.parseInt(br.readLine());
                 z=Integer.parseInt(br.readLine());
                System.out.println(c.mul(y,z));
                break;
                    }
            case 4:
                System.out.println("enter two numbers:");
                 y=Integer.parseInt(br.readLine());
                 z=Integer.parseInt(br.readLine());
                System.out.println(c.div(y,z));
                break;
              default:
                System.out.println("you havn't entered anything");
                break;
            }
        }
        catch (MalformedURLException murle) {
            System.out.println();
            System.out.println(
              "MalformedURLException");
            System.out.println(murle);
        }
        catch (RemoteException re) {
            System.out.println();
            System.out.println("RemoteException");
            System.out.println(re);
        }
        catch (NotBoundException nbe) {
            System.out.println();
            System.out.println("NotBoundException");
            System.out.println(nbe);
        }
        catch (java.lang.ArithmeticException ae) {
            System.out.println();
            System.out.println(
             "java.lang.ArithmeticException");
            System.out.println(ae);
          
        }
    }
}


EXECUTION PROCEDURE:

 1)For the execution of the rmi program, we need to set the classpath at the environment variables( This at mycomputer properties on windows operating systems)
  


 2)Compile the Calculator Interface and Calculator Implementation programs:

c:\>rmi>javac Calculator.java
c:\>rmi>javac CalculatorImpl.java 

Screen shot:
 
IT CAN EXECUTE SUCCESS FULLY. SOME TIMES YOU CAN FIND AN ERROR
"CAN NOT FIND THE SYMBOL"--> IF YOU ENCOUNTER THIS KIND OF ERROR,THE CLASSPATH  IS NOT PROPERLY SET AT THE ENVIRONMENT VARIABLES

THE ERROR SHOWS LIKE THIS:

3)COMPILE THE IMPLEMENTATION CLASS USING RMI COMPILER (RMIC)

C:\>rmi>rmic CalculatorImpl   ((hit enter))

  THIS GENERATES A "STUB CLASS" AT THE SAME RMI DIRECTORY IN YOUR C DRIVE

4)COMPILE THE CALCULATOR SERVER AND CALCULATOR CLIENT PROGRAMS AT THE CMD PROMPT
(SEE THE ABOVE FIGURE FOR THE TASKS WHAT WE HAVE DONE TILL NOW)

5)START RMI REGISTRY AT CMD PROMPT BY TYPING

C:\>RMI>start rmiregistry  

-- a new window appers on the screen like below --

6) START THE CALCULATOR SERVER BY TYPING THE CMD

C:\>RMI>start java CalculatorServer.java

(again a new window appers like below)


7)NEXT AND LOST STEP IS RUN THE CALCULATORCLIENT

C:\>RMI>java CalculatorClient

(THE OUT PUT WINDOW APPEARS LIKE THIS:)


No comments:

Post a Comment