The naming convention details depend on whether or not the instance variable representing a bean property is an array or not. Bean properties represented as arrays are known as indexed properties. First, let s consider the case in which bean properties are not represented as arrays. Coding Accessor Methods for Non-Array Bean Properties The following is a description of the naming convention for accessor methods of non-array bean properties: Given a variable named anInstanceVariable, declared as follows: private SomeClassOrPrimitiveType anInstanceVariable ; the get method that reads the variable s name can be coded as follows: public SomeClassOrPrimitiveType getAnInstanceVariable() { return anInstanceVariable ; } Notice the following about the variable declaration and the get method: . The variable anInstanceVariable is declared private. The private declaration insures that users of your bean cannot access the bean s instance variables at will. The bean user has to access the instance variables through an approved interface. . The get method is declared public. The get method is part of the approved interface the bean exposes to the outside world. . The get method takes no arguments. . The name of the get method is the word “get” followed by the name of the instance variable with the first letter of the variable name capitalized. However, when the instance variable is of type boolean, you may name the method starting with the word is instead of the word get. . The get method returns some element of the same class or primitive data type as the instance variable. The preceding list of restrictions is required for bean use. Suppose you coded the getAnInstanceVariablemethod without following the rules? For example: public SomeClassOrPrimitiveTypegetAnInstanceVariable( Class1 objClass1 ) { return anInstanceVariable ; } You could invoke the method to get the instance variable. However, JavaBean tools would not know the preceding coded method is a get method. The difference in signatures between the no-argument get method and the method coded above would “fool” the bean tool. Stated differently, the preceding coded method does not follow the standard for coding JavaBeans. To the bean tool, the above method is not related to a bean property. One common mistake is to forget that the first letter of the instance variable name included in the set method name must be capitalized. Hence, the method header coded as follows fails the naming standard: public SomeClassOrPrimitiveType getanInstanceVariable() When you access bean properties in your JSPs, you must code get methods according to the convention described previously, or else the JSP engine, as with bean tools, will fail to recognize the method as a get method. In the preceding example, the get method merely returns the instance variable. Of course, you may code methods
For the first time, E-commerce websites allow small and large companies to actually compete on a level playing field.We highly recommend you to visit ecommerce website hosting.

Leave a Reply