Java


In [1]:
package test.beaker;

import java.util.Date;
import java.text.SimpleDateFormat;

public class BeakerTest {
  private Date _date;
  private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
  
  public BeakerTest() {
    _date = new Date();
  }

  public String getDateTxt() {
    return "Today:" + sdf.format(_date);
  }

  public String getDateUpperCaseTxt() {
    return getDateTxt().toUpperCase();
  }

}


Out[1]:
test.beaker.BeakerTest

In [2]:
package test.beaker;

BeakerTest bt = new BeakerTest();
return bt.getDateTxt();


Out[2]:
Today:2017-04-07T23:36-0400

In [ ]:
%%groovy
package test.beaker;

bt = new BeakerTest();
bt.getDateUpperCaseTxt();


Cell magic %%groovy not found

In [ ]:
%%javascript
console.log("hi mom");


Out[ ]:

In [5]:
try {
  return NamespaceClient.getBeaker().get("autovariable");
} catch(Exception e) { }
return "ERROR! autotranslation not working";


ERROR: 1 compilation error(s)

error at line 2: cannot find symbol
  symbol:   variable NamespaceClient
  location: class com.twosigma.beaker.javash.bkrfbdbb63e.BeakerWrapperClass1261714175
   return NamespaceClient.getBeaker().get("autovariable
          ^              ^                               

In [12]:
import java.util.List;
import java.util.ArrayList;
import com.twosigma.beaker.chart.xychart.Plot;
import com.twosigma.beaker.chart.xychart.plotitem.*;
import com.twosigma.beaker.chart.Color;

Plot p = new Plot();

p.setTitle("this is a Java plot");

Bars b = new Bars();

List<Number> yList = new ArrayList<Number>();
yList.add(2);
yList.add(5);
yList.add(4);
yList.add(8);

b.setY(yList);
b.setColor(Color.blue);
b.setWidth(0.5);

p.add(b);
  
return p;


Out[12]:


In [7]:
package test.beaker;
interface DateGetter {
   public String getDateTxt();
}


Out[7]:
test.beaker.DateGetter

In [8]:
package test.beaker;
public class DG2 extends BeakerTest implements DateGetter {
}


Out[8]:
test.beaker.DG2

Using the classpath to load a jar


In [22]:
System.out.println("The Groovy working folder is :");
System.out.println(java.nio.file.Paths.get(".").toAbsolutePath().normalize().toString());
System.out.println("BeakerXClasspathTest.jar exists in this folder");


The Groovy working folder is :
/Users/spot/src/beakerx/demoFiles
BeakerXClasspathTest.jar exists in this folder
Out[22]:
null

In [21]:
BeakerXClasspathTest t = new BeakerXClasspathTest();
System.out.println(com.beaker.BeakerXClasspathTest.staticTest);
System.out.println(t.getObjectTest());


static_123
object_123
Out[21]:
null

In [1]:
System.out.println("The Groovy working folder is :");


The Groovy working folder is :
Out[1]:
null

In [ ]: