{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Java"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"test.beaker.BeakerTest"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"package test.beaker;\n",
"\n",
"import java.util.Date;\n",
"import java.text.SimpleDateFormat;\n",
"\n",
"public class BeakerTest {\n",
" private Date _date;\n",
" private SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mmZ\");\n",
" \n",
" public BeakerTest() {\n",
" _date = new Date();\n",
" }\n",
"\n",
" public String getDateTxt() {\n",
" return \"Today:\" + sdf.format(_date);\n",
" }\n",
"\n",
" public String getDateUpperCaseTxt() {\n",
" return getDateTxt().toUpperCase();\n",
" }\n",
"\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"Today:2017-04-07T23:36-0400"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"package test.beaker;\n",
"\n",
"BeakerTest bt = new BeakerTest();\n",
"return bt.getDateTxt();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Cell magic %%groovy not found"
]
}
],
"source": [
"%%groovy\n",
"package test.beaker;\n",
"\n",
"bt = new BeakerTest();\n",
"bt.getDateUpperCaseTxt();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%javascript\n",
"console.log(\"hi mom\");"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"ename": "ERROR",
"evalue": " 1 compilation error(s)",
"output_type": "error",
"traceback": [
"\u001b[0;31mERROR: 1 compilation error(s)",
"\u001b[0;31m",
"\u001b[0;31merror at line 2: cannot find symbol",
"\u001b[0;31m symbol: variable NamespaceClient",
"\u001b[0;31m location: class com.twosigma.beaker.javash.bkrfbdbb63e.BeakerWrapperClass1261714175",
"\u001b[0;31m return NamespaceClient.getBeaker().get(\"autovariable",
"\u001b[0;31m ^ ^ "
]
}
],
"source": [
"try {\n",
" return NamespaceClient.getBeaker().get(\"autovariable\");\n",
"} catch(Exception e) { }\n",
"return \"ERROR! autotranslation not working\";"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import java.util.List;\n",
"import java.util.ArrayList;\n",
"import com.twosigma.beaker.chart.xychart.Plot;\n",
"import com.twosigma.beaker.chart.xychart.plotitem.*;\n",
"import com.twosigma.beaker.chart.Color;\n",
"\n",
"Plot p = new Plot();\n",
"\n",
"p.setTitle(\"this is a Java plot\");\n",
"\n",
"Bars b = new Bars();\n",
"\n",
"List yList = new ArrayList();\n",
"yList.add(2);\n",
"yList.add(5);\n",
"yList.add(4);\n",
"yList.add(8);\n",
"\n",
"b.setY(yList);\n",
"b.setColor(Color.blue);\n",
"b.setWidth(0.5);\n",
"\n",
"p.add(b);\n",
" \n",
"return p;"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"test.beaker.DateGetter"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"package test.beaker;\n",
"interface DateGetter {\n",
" public String getDateTxt();\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"test.beaker.DG2"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"package test.beaker;\n",
"public class DG2 extends BeakerTest implements DateGetter {\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## Using the classpath to load a jar"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Groovy working folder is :\n",
"/Users/spot/src/beakerx/demoFiles\n",
"BeakerXClasspathTest.jar exists in this folder\n"
]
},
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"System.out.println(\"The Groovy working folder is :\");\n",
"System.out.println(java.nio.file.Paths.get(\".\").toAbsolutePath().normalize().toString());\n",
"System.out.println(\"BeakerXClasspathTest.jar exists in this folder\");"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"static_123\n",
"object_123\n"
]
},
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BeakerXClasspathTest t = new BeakerXClasspathTest();\n",
"System.out.println(com.beaker.BeakerXClasspathTest.staticTest);\n",
"System.out.println(t.getObjectTest());"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Groovy working folder is :\n"
]
},
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"System.out.println(\"The Groovy working folder is :\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"beakerx_kernel_parameters": {
"classpath": [
"BeakerXClasspathTest.jar"
],
"imports": [
"com.twosigma.beaker.chart.xychart.*",
"com.twosigma.beaker.easyform.EasyForm",
"com.twosigma.beaker.chart.Filter",
"com.twosigma.beaker.chart.Color",
"com.twosigma.beaker.NamespaceClient",
"com.twosigma.beaker.fileloader.CsvPlotReader",
"com.twosigma.beaker.jvm.object.OutputCell",
"com.twosigma.beaker.chart.categoryplot.plotitem.*",
"com.twosigma.beaker.chart.categoryplot.*",
"com.twosigma.beaker.chart.xychart.plotitem.*",
"com.twosigma.beaker.table.*",
"com.twosigma.beaker.chart.GradientColor",
"com.twosigma.beaker.chart.legend.*",
"com.twosigma.beaker.chart.histogram.*",
"com.twosigma.beaker.chart.heatmap.HeatMap",
"com.beaker.BeakerXClasspathTest"
]
},
"kernelspec": {
"display_name": "Java",
"language": "java",
"name": "java"
},
"language_info": {
"codemirror_mode": "text/x-java",
"file_extension": ".java",
"mimetype": "",
"name": "Java",
"nbconverter_exporter": "",
"pygments_lexer": "",
"version": "1.8.0_111"
}
},
"nbformat": 4,
"nbformat_minor": 2
}