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

Object Command 

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 using object command in beanshell script.

File Name  :  
/BEAN_SHELL001/config/obj.bsh 
   
myObj = object();
myObj.name = "Sriram";
myObj.age = 2;

print("Name : " + myObj.name);
print("Age  : " + myObj.age);
   

File Name  :  
com/bethecoder/tutorials/bean_shell/commands/EmptyObjectTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.bean_shell.commands;

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class EmptyObjectTest {

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

}
   

It gives the following output,
Name : Sriram
Age  : 2



 
  


  
bl  br