Wednesday 24 February 2016

Java beans || Advantages || creating and running java beans

What is a java bean?

A java bean is a software component that has been designed to be reusable in a variety of different environments.There is no restriction on the capability of a bean. It may perform a simple function such as obtaining an inventory value or a complex function, such as forecasting the performance of a stock portfolio.

Why java beans:-

To design any hardware different components such as registers, capacitors, and inductors can be integrated. All these are reusable, we can use same circuit or register to other hardware because the behavior of these components is understood and documented.
                                Similarly, the same functionality can be achieved using a component architecture that allows programmers to reuse by writing once. The java bean provides such an architecture.

Advantages of java beans:-

  • A java bean obtains all the benefits of java’s “write-once, run-any ware” paradigm
  • The properties, events, and methods of a bean that are exposed to another application can be controlled.
  • Auxiliary software can be provided to help configure a bean.
  • The configuration settings of a bean can be saved in persistent storage and restore at a later time.
  • A bean may register to receive from other objects and can generate events that are sent to other objects.

Creating and Running Java Beans 

a java bean is a reusable software component that follow the rule of "write-once and run any ware". creating a java bean is a simple procedure and it include the following steps.

  • create a code for your java bean
  • create manifest and jar files for your bean
  • finally compiling the bean

creating a code for your bean:-


this is the first step in the creating or running a java bean. you must create a java program by using java bean properties such as simple and indexed properties.

after creating program code compile the java program and it generates a .class file for your bean code. in order to run the java bean it is necessary your computer must already have JDK and BDK installed on your computer and you must set the environmental variables before running java bean.

create a folder with your program name in C:\Program Files\Beans\demo\sunw\demo ( i have created folder name as Textdemo)

the following is the java program for textdemo
 package sunw.demo.textdemo;  
 import java.awt.*;  
 public class Textdemo extends Canvas  
 {  
      private String msg;  
      public Textdemo()  
      {  
           msg="dvrtechnopark.com";  
      }  
      public String getMasg(){  
           return msg;  
      }  
      public void setMsg(String msg) {  
           this.msg=msg;  
      }  
      public void paint(Graphics g)  
      {  
           FontMetrics fm=g.getFontMetrics();  
           int w=fm.stringWidth(msg)+30;  
           int h=fm.getHeight()+30;  
           Dimension dim=new Dimension(w,h);  
           int x=(dim.height+fm.stringWidth(msg))/2;  
           int y=(dim.height+fm.getMaxAscent());  
           g.drawString(msg,x,y);  
           //g.drawrect(0,0,w-1,h-1);  
      }  
 }  



compile your java program it creates a .class file and place it in C:\Program Files\Beans\demo


create manifest and jar files for your bean

then create a manifest file. the manifest file can be created as  by giving the path where your .class file is located as

Name:-\sunw\demo\textdemo\Textdemo.class
Java-Bean:True

 compiling the bean/creating jar file

 now compile the java bean as shown

javac cvf -textdemo.jar C:\Program Files\Beans\demo C:\Program Files\Beans\demo\sunw\demo\textdemo.;

the it will create a textdemo.jar for your java bean program and when your click the Run Batchfile in bean-box at the left side you will see the textdemo component and when your click on it it will display as




 





0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top