{"id":65926,"date":"2021-07-17T04:10:05","date_gmt":"2021-07-17T08:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/ejb-3-statefull-ejb-java-short-notes\/"},"modified":"2021-07-17T04:10:05","modified_gmt":"2021-07-17T08:10:05","slug":"ejb-3-statefull-ejb-java-short-notes","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=65926","title":{"rendered":"EJB 3: Statefull EJB #Java Short Notes"},"content":{"rendered":"<p><pre style='font-size:13;padding-left:10px'>States need to be maintained between calls. In EJB3 all beans are homeless [no home interface]\/\/ShoppingCartBean.javaimport java.io.Serializable;import java.util.HashMap;import javax.ejb.Remove;import javax.ejb.Stateful;import javax.ejb.Remote;@Stateful@Remote(ShoppingCart.class)public class ShoppingCartBean implements ShoppingCart, Serializable{   private HashMap cart = new HashMap();   public void buy(String product, int quantity)   {      if (cart.containsKey(product))      {         int currq = cart.get(product);         currq += quantity;         cart.put(product, currq);      }      else      {         cart.put(product, quantity);      }   }   public HashMap getCartContents()   {      return cart;   }   @Remove   public void checkout()   {      System.out.println(\"To be implemented\");   }}\/\/ShoppingCart.java\/\/remote interfaceimport java.util.HashMap;import javax.ejb.Remove;public interface ShoppingCart{   void buy(String product, int quantity);   HashMap getCartContents();   @Remove void checkout();}\/\/client\/\/Client.java\/\/client uses JNDI to look up for EJB servicesimport java.util.HashMap;import javax.naming.InitialContext;import org.jboss.tutorial.stateful.bean.ShoppingCart;public class Client{   public static void main(String[] args) throws Exception   {      InitialContext ctx = new InitialContext();      ShoppingCart cart = (ShoppingCart) ctx.lookup(\"ShoppingCartBean\/remote\");      System.out.println(\"Buying 1 memory stick\");      cart.buy(\"Memory stick\", 1);      System.out.println(\"Buying another memory stick\");      cart.buy(\"Memory stick\", 1);      System.out.println(\"Buying a laptop\");      cart.buy(\"Laptop\", 1);      System.out.println(\"Print cart:\");      HashMap fullCart = cart.getCartContents();      for (String product : fullCart.keySet())      {         System.out.println(fullCart.get(product) + \"     \" + product);      }      System.out.println(\"Checkout\");      cart.checkout();      System.out.println(\"Should throw an object not found exception        by invoking on cart after @Remove method\");      try      {         cart.getCartContents();      }      catch (javax.ejb.EJBNoSuchObjectException e)      {         System.out.println(\"Successfully caught no such object exception.\");      }   }}<\/pre>\n<\/p>\n<p> From: http:\/\/sitestree.com\/?p=4833<br \/> Categories:Java Short Notes<br \/>Tags:<br \/> Post Data:2008-11-20 09:48:27<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>States need to be maintained between calls. In EJB3 all beans are homeless [no home interface]\/\/ShoppingCartBean.javaimport java.io.Serializable;import java.util.HashMap;import javax.ejb.Remove;import javax.ejb.Stateful;import javax.ejb.Remote;@Stateful@Remote(ShoppingCart.class)public class ShoppingCartBean implements ShoppingCart, Serializable{ private HashMap cart = new HashMap(); public void buy(String product, int quantity) { if (cart.containsKey(product)) { int currq = cart.get(product); currq += quantity; cart.put(product, currq); } else { cart.put(product, &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=65926\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-65926","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":65938,"url":"http:\/\/bangla.sitestree.com\/?p=65938","url_meta":{"origin":65926,"position":0},"title":"EJB 3: Entity Bean Basic #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Plain Java objects with persistence storage. They are not remotable and must be accessed through the new javax.persistence.EntityManager service. An entity bean implementation is provided in the following three files\/classesBeansOrder.javaLineItem.javaEntity ManagerShoppingCartBean.java\/\/Order.javaimport javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.OneToMany;import javax.persistence.Table;import javax.persistence.Id;import javax.persistence.CascadeType;import javax.persistence.FetchType;import java.util.ArrayList;import java.util.Collection;@Entity@Table(name = \"PURCHASE_ORDER\")public class Order implements\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65922,"url":"http:\/\/bangla.sitestree.com\/?p=65922","url_meta":{"origin":65926,"position":1},"title":"EJB 3: Stateless Bean #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 17, 2021","format":false,"excerpt":"No need to maintain the state of a bean between calls. \/\/CalculatorBean.java@Statelesspublic class CalculatorBean implements CalculatorRemote, CalculatorLocal{ public int add(int x, int y) { return x + y; } public int subtract(int x, int y) { return x - y; }}\/\/CalculatorRemote.javaimport javax.ejb.Remote;@Remotepublic interface CalculatorRemote extends Calculator{}\/\/CalculatorLocal.java import javax.ejb.Local;@Localpublic interface CalculatorLocal\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27192,"url":"http:\/\/bangla.sitestree.com\/?p=27192","url_meta":{"origin":65926,"position":2},"title":"JTable Examples #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 13, 2021","format":false,"excerpt":"# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; \/** Simple JTable example that uses a String array for the * table header and table data. * *\/ public class JTableSimpleExample extends JFrame { public static void main(String[] args) { new\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":66328,"url":"http:\/\/bangla.sitestree.com\/?p=66328","url_meta":{"origin":65926,"position":3},"title":"Accessing EJBS from Servlet #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"EJBs can be used to create enterprise applications like banking systems. Clients will interact with such systems for operations like: withdraw cash, transfer cash, pay bills When clients directly access EJBs it poses concerns such as: security risks, firewall blocking, EJB architecture becomes transparent to the clients Servlets can act\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":65926,"position":4},"title":"Multithreaded Graphics and Double Buffering #Programming Code Examples #Java\/J2EE\/J2ME #Java Threads","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { ... public void run() { Ship s; for(int\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10271,"url":"http:\/\/bangla.sitestree.com\/?p=10271","url_meta":{"origin":65926,"position":5},"title":"Printing in Java 2","author":"","date":"August 26, 2015","format":false,"excerpt":"\u00a0\u00a0 * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o PrintExample.java Demonstrates printing a Graphics2D object. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.print.*; \/** An example of a printable window in Java 1.2. The key point \u00a0*\u00a0 here is that any component is printable in Java 1.2. \u00a0*\u00a0 However, you have to be careful to\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65926"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65926\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65926"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}