Skip to main content

Posts

EJB3 | Stateless session bean

To build a statelesss session bean in EJB3, you need to create one interafce and on class. Interface is implemented by class and methods declared in the interaface are available to client for remote access. Bean class and interaface should be public. Bean class is annotated with the annotation @Stateless(mappedName="something") and interafce is annotated with @Remote annotation. Both are compiled and packed in jar file. Coding for Remote Interface package p1; import javax.ejb.Remote; @Remote public interface AdderIntf{     int add(int x,int y); } Coding for Bean class package p1; import javax.ejb.Stateless; @Stateless(mappedName="abc") public class Adder implements AdderIntf{     public int add(int x,int y){         System.out.println("x="+x+" , y="+y);         int z=x+y;         return z;     } } Both are compiled and packaged in jar file. you can y...

Calculator in java swing

import  javax.swing. * ; import  java.awt. * ; import  java.awt.event. * ; import  java.io. * ; class  gui1 {      static   double  a = 0 ;      static   int  op = 0 ;      public   static   void   main ( String  ar []){                   JFrame  f1 = new   JFrame ( "Calculator" ) ;         f1. setLayout ( null ) ;          final   JTextField  t1 = new   JTextField ( 100 ) ;         t1. setBounds ( 10 , 10 , 200 , 30 ) ;          JButton  b0 = new   JButton ( "0" ) ;          JButton  b1 = new   JButton ( "1" ) ;   ...

JUnit test : example

Here following is the class to be tested using JUnit public   class  MyClass  {      public   int   add( int  a, int  b ){          return  a + b;     }      public   int   sub( int  a, int  b ){          return  a - b;     }      public   int   mul( int  a, int  b ){          return  a * b;     }      public   int   div( int  a, int  b ){          return  a / b;     } } class that contains three testing method to test add method of class MyClass import   static  org.junit.Assert.assertEquals; import  org.junit. * ; public ...

String hadnling

String is the sequence of character represented by the object of String class in java. Two other classes’ string buffer and string builder can be used for same thing. String object provides some predefined method those are used to manipulate the string. String object is said to be the immutable this means that you can not manipulate the string object. But you can work with that object. When you manipulate the string object then new string object is created and it consists of manipulated contents. But it is hard to observe by programmer without experience. Here to solve this problem you can use the String buffer class to create the string object in which you can manipulate the string contents with the same object. That is the object of string class the mutable. String buffer is the thread safe. Another class to create the mutable string objects is string builder class. But it is no thread safe. Creating String There are many ways to create the string object 1 You can dec...

Java : Using Runtime to Play song in media player

import java.io. * ; class FileDemo1 { public static void main( String ar []) throws Exception { //Runtime.getRuntime().exec("D:\\Program Files\\Windows Media Player\\wmplayer.exe"); Runtime . getRuntime().exec( "D:\\Program Files\\Windows Media Player\\wmplayer.exe \"F:\\V\\SONGS\\Dostana\\desi girl.mp3\"" ) ; } }

Java : Properties Class

import java.util. * ; import java.io. * ; class PropertiesDemo { public static void main ( String ar []) { Properties prop = new Properties () ; try { prop. setProperty ( "my.name" , "ABC xyz" ) ; prop. setProperty ( "my.phone" , "3453545" ) ; FileOutputStream fout = new FileOutputStream ( "Prop.properties" ) ; prop. store ( fout, "My Properties" ) ; } catch ( Exception e ){} } } ****************************************************************************** import java.util. * ; import java.io. * ; class PropertiesDemo2 { public static void main ( String ar []) { Properties prop = new Properties () ; try...