tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java Scripting > BeanShell > Static Imports

Static Imports 

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell is a natural scripting language for Java. This requires the library bsh-2.0b4.jar to be in classpath. The following example shows importing static properties and methods in beanshell script.

File Name  :  
/BEAN_SHELL001/config/static_import.bsh 
   
static import  java.lang.Integer.*;
static import  java.lang.Math.*;

print("MIN_VALUE : " + MIN_VALUE);
print("MAX_VALUE : " + MAX_VALUE);
    
print("2 pow 3 : " + pow(23));
print("sqrt(36) : " + sqrt(36));
   

File Name  :  
com/bethecoder/tutorials/bean_shell/StaticImportTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.bean_shell;

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class StaticImportTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();
    InputStreamReader reader = new InputStreamReader(
        StaticImportTest.class.getClassLoader()
        .getResourceAsStream("static_import.bsh"));

    interpreter.eval(reader);
  }

}
   

It gives the following output,
MIN_VALUE : -2147483648
MAX_VALUE : 2147483647
2 pow 3 : 8.0
sqrt(36) : 6.0


                    Print

   



Books Recommendation

 
 
bl  br