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

Switch Case 

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 switch case in beanshell script.

File Name  :  
/BEAN_SHELL001/config/switch.bsh 
   
switch(str
{
  case "ONE":
    print("11111111111111");
    break;
  case "TWO":
    print("22222222222222");
    break;
  case "THREE":
    print("33333333333333");
    break;  
  default:
}
   

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

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class SwitchTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();
    interpreter.set("str""TWO");

    InputStreamReader reader = new InputStreamReader(
        SwitchTest.class.getClassLoader()
        .getResourceAsStream("switch.bsh"));
    interpreter.eval(reader);
  }

}
   

It gives the following output,
22222222222222



 
  


  
bl  br