{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Java\n", "\n", "Java is the mother of all JVM languages, first released in 1995 after years of development by Sun Microsystems. BeakerX uses [OpenJDK](http://openjdk.java.net/) for Java and all the kernels.\n", "\n", "BeakerX supports Java cells that define classes, which can be used by other JVM based cells.\n", "One cell is equivalent to a Java compilation unit and can contain a single class, or a sequence of statements." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%import com.twosigma.beakerx.widget.FloatSlider" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "com.twosigma.beaker.javash.bkr4480ff70.Controls" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "public class Controls {\n", "public static final FloatSlider w = new FloatSlider();\n", "//w.value = {10,40};\n", " static{\n", "w.setOrientation(\"horizontal\");\n", "w.setMax(100.0);\n", "w.setMin(-100.0);\n", " }\n", "//w.orientation = \"vertical\"\n", "}" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c26eece4-a2ee-4a61-a62c-0986090e7099", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "return Controls.w;" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-53.6" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "return Controls.w.getValue();" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%classpath add mvn org.json json 20180813" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "com.twosigma.beaker.javash.bkr3746a81e.Vector" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import java.util.Arrays;\n", "import java.lang.reflect.Array;\n", "\n", "public class Vector<V>{\n", "\n", " public final static int DEFAULT_SIZE= 8;\n", " protected V[] data;\n", " protected int size;\n", " private static final int a=10;\n", " private static final float b=1.f;\n", "\n", " public Vector(){\n", " this(DEFAULT_SIZE);\n", " }\n", " public Vector(int initSize){\n", " data= (V[]) new Object[initSize];\n", " size= 0;\n", " }\n", " public void add(V v){\n", " if(size == data.length){ grow();}\n", " data[size]= v;\n", " ++size; \n", " }\n", " public V get(int i){\n", " if (i >= size){\n", " throw new IndexOutOfBoundsException(\"TODO\");\n", " }\n", " return data[i];\n", " }\n", " public void set(int i, V v){\n", " if (i >= size){\n", " throw new IndexOutOfBoundsException(\"TODO\");\n", " }\n", " data[i]= v;\n", " }\n", " \n", " private static int newLength(int oldLength){\n", " return ((int) Math.ceil(oldLength*b))+a;\n", " }\n", "\n", " private void grow(){\n", " data= Arrays.copyOf(data, Math.max(data.length+1, newLength(data.length)));\n", " \n", " }\n", " public int indexOf(V toFind){\n", " for(int i=0; i != size; ++i){\n", " if(toFind.equals(data[i])){\n", " return i;\n", " }\n", " }\n", " return -1;\n", " }\n", " public boolean contains(V toFind){\n", " return indexOf(toFind) != -1;\n", " }\n", " @Override\n", " public String toString(){\n", " String res=\"\";\n", " for (int i=0; i != size; ++i){\n", " res+= data[i]+\",\";\n", " }\n", " return \"[\"+res+\"]\";\n", " }\n", "\n", " public Object[] toArray(){\n", " return Arrays.copyOf(data, size);\n", " }\n", " public <T> T[] toArray(T[] a){\n", " if(a.length < size){\n", " return (T[])Arrays.copyOf(data, size, a.getClass());\n", " }\n", " //System.arraycopy(data, 0, a, 0, size);\n", " for(int i=0; i != size; ++i){\n", " a[i]= (T)data[i]; \n", " }\n", " if(a.length > size){\n", " a[size]= null;\n", " }\n", " return a;\n", " }\n", " public static void main(String[] args){\n", " Vector<Integer> v= new Vector<Integer>();\n", " for(int i=0; i != 32; ++i){\n", " v.add(new Integer(i));\n", " }\n", " System.out.println(v);\n", " Integer[] a= v.toArray(new Integer[v.size]);\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "null" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Vector<Integer> v= new Vector<Integer>();\n", "for(int i=0; i != 100000; ++i){\n", " v.add(0);\n", "}" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "45 ms ± 25 ms per loop (mean ± std. dev. of 10 run, 3 loop each)\n" ] } ], "source": [ "%%timeit -r10 -n3\n", "Vector<Integer> v= new Vector<Integer>();\n", "for(int i=0; i != 10000; ++i){\n", " v.add(0);\n", "}" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "55 ms ± 19 ms per loop (mean ± std. dev. of 2 run, 3 loop each)\n" ] } ], "source": [ "%%timeit -r2 -n3 v.contains(1);" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "com.twosigma.beaker.javash.bkr3746a81e.KeyValue" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "public class KeyValue<K, V>{\n", " public final K key;\n", " public final V value;\n", " public KeyValue(K k, V v){\n", " key= k;\n", " value= v;\n", " }\n", " public boolean equals(Object o){\n", " System.err.print(o);\n", " if(!(o instanceof KeyValue)){\n", " return false;\n", " }\n", " KeyValue<K, V> other= (KeyValue<K, V>)o;\n", " return key.equals(other.key) && value.equals(other.value);\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "com.twosigma.beaker.javash.bkr3746a81e.NaiveMap" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "public class NaiveMap<Key, Value> extends Vector<KeyValue<Key, Value>> {\n", "\n", " private int indexOfKey(Key k){\n", " for(int i=0; i != size; ++i){\n", " if(k.equals(get(i).key)){\n", " return i;\n", " }\n", " }\n", " return -1;\n", " }\n", " public void put(Key k, Value v){\n", " KeyValue<Key, Value> kv= new KeyValue<Key,Value>(k, v);\n", " int i= indexOfKey(k);\n", " if (i != -1){\n", " set(i, kv);\n", " }else{\n", " add(kv);\n", " }\n", " }\n", " public Value get(Key k){\n", " return get(indexOfKey(k)).value; // TODO handle not found\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Debian\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "NaiveMap<String, String> nm= new NaiveMap();\n", "//import java.util.Map;\n", "//import java.util.HashMap;\n", "//Map<String, String> nm= new HashMap<String, String>();\n", "nm.put(\"Gnu/Linux\", \"Debian\");\n", "System.out.println(nm.get(\"Gnu/Linux\"));\n", "for(int i=0; i != 100000; ++i){\n", " String k=\"k\"+i;\n", " String v=\"v\"+i;\n", " nm.put(k, v);\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "61 ms ± 10 ms per loop (mean ± std. dev. of 2 run, 3 loop each)\n" ] } ], "source": [ "%%timeit -r2 -n3 nm.get(\"test\");" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "45 ms ± 17 ms per loop (mean ± std. dev. of 2 run, 3 loop each)\n" ] } ], "source": [ "%%timeit -r2 -n3 nm.get(\"test\");" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "latitude: 48.867413, longitude: 2.347572\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import org.json.JSONObject;\n", "import org.json.JSONArray;\n", "\n", "import java.io.FileReader;\n", "import java.io.BufferedReader;\n", "\n", "import java.io.FileNotFoundException;\n", "import java.io.IOException;\n", "\n", "import java.io.InputStreamReader;\n", "import java.net.URL;\n", "import java.net.URLEncoder;\n", "import java.util.Collection;\n", "import java.util.List;\n", "import java.util.ArrayList;\n", "import java.util.Scanner;\n", "\n", "String adr=\"60, Rue Réaumur\";//\"28, rue notre dame des champs\";\n", "double score= -Double.MAX_VALUE;\n", "double latitude= Double.NaN;\n", "double longitude= Double.NaN;\n", " URL url= new URL(\"https://api-adresse.data.gouv.fr/search/?q=\"+URLEncoder.encode(adr, \"UTF-8\")+\"&lat=48.8592112&lon=2.338452\");\n", " try(BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {\n", " JSONArray fs= new JSONObject(br.readLine()).getJSONArray(\"features\");\n", " for(int i=0; i != fs.length(); ++i){\n", " JSONObject f= fs.getJSONObject(i);\n", " if(f.getJSONObject(\"properties\").getString(\"city\").equals(\"Paris\")){\n", " if(f.getJSONObject(\"properties\").getDouble(\"score\")> score){\n", " score= f.getJSONObject(\"properties\").getDouble(\"score\");\n", " longitude=f.getJSONObject(\"geometry\").getJSONArray(\"coordinates\").getDouble(0); \n", " latitude=f.getJSONObject(\"geometry\").getJSONArray(\"coordinates\").getDouble(1); \n", " }\n", " }\n", " \n", " }\n", "System.out.println(\"latitude: \"+latitude+\", longitude: \"+longitude);\n", " //JSONArray res = new JSONObject(resp).getJSONArray(\"features\").getJSONObject(0).getJSONObject(\"geometry\").getJSONArray(\"coordinates\");\n", " //System.out.println(res);//longitude , latitude\n", " }\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "test.beaker.BeakerTest" ] }, "execution_count": 3, "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": {}, "outputs": [ { "data": { "text/plain": [ "com.twosigma.beaker.javash.bkr66b07261.GeoPoint" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import java.io.FileReader;\n", "import java.io.BufferedReader;\n", "\n", "import java.io.FileNotFoundException;\n", "import java.io.IOException;\n", "\n", "import java.io.InputStreamReader;\n", "import java.net.URL;\n", "import java.net.URLEncoder;\n", "\n", "import org.json.JSONObject;\n", "import org.json.JSONArray;\n", "\n", "import java.util.Collection;\n", "import java.util.List;\n", "import java.util.ArrayList;\n", "import java.util.Map;\n", "import java.util.HashMap;\n", "import java.util.Scanner;\n", "\n", "public class GeoPoint{\n", " public final double latitude;\n", " public final double longitude;\n", " public final Map<GeoPoint, Integer> neighborToDistance;\n", " \n", " public static List<GeoPoint> data= new ArrayList<GeoPoint>();\n", " \n", " public GeoPoint(double latitude, double longitude){\n", " this.latitude= latitude;\n", " this.longitude= longitude;\n", "\tneighborToDistance= new HashMap<GeoPoint, Integer>();\n", " }\n", "\n", " public double distanceTo(GeoPoint other){\n", " return distanceTo(other.latitude, other.longitude);\n", " }\n", " public double distanceTo(double latitude, double longitude){\n", " double earthRadius= 6371e3;// in meters\n", " double phi1=Math.toRadians(this.latitude);\n", " double phi2=Math.toRadians(latitude);\n", " double deltaPhi=Math.toRadians(latitude- this.latitude);\n", " double deltaLambda= Math.toRadians(longitude- this.longitude);\n", " double a= Math.sin(deltaPhi/2) * Math.sin(deltaPhi/2) +\n", " Math.cos(phi1) * Math.cos(phi2) * Math.sin(deltaLambda/2) * Math.sin(deltaLambda/2);\n", " double c= 2* Math.atan2(Math.sqrt(a), Math.sqrt(1-a));\n", " return earthRadius * c;\n", " }\n", " public String toString(){\n", " return \"GeoPoint: \"+super.toString()+\"{latitude: \"+latitude+\", longitude: \" + longitude+\", nb of neighbors\"+neighborToDistance.size()+\"}\";\n", " }\n", " public static GeoPoint closerTo(double latitude, double longitude, double deltaD, Collection<GeoPoint> points){\n", " GeoPoint res=null;\n", " double minD= Double.POSITIVE_INFINITY;\n", " for(GeoPoint point : points){\n", " double currentD= point.distanceTo(latitude, longitude);\n", " if((currentD < minD) && (currentD > deltaD) ){\n", " minD= currentD;\n", " res= point;\n", " }\n", " }\n", " return res;\n", " }\n", " public static GeoPoint findByName(String name){\n", "\t GeoPoint res= null;\n", " try{\n", " \n", " URL url= new URL(\"https://api-adresse.data.gouv.fr/search/?q=\"+URLEncoder.encode(name, \"UTF-8\")+\"&postcode=75000\");\n", " try(BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {\n", " JSONArray coords = new JSONObject(br.readLine()).getJSONArray(\"features\").getJSONObject(0).getJSONObject(\"geometry\").getJSONArray(\"coordinates\");\n", " res= new GeoPoint(coords.getDouble(0), coords.getDouble(1));\n", " }catch(Exception e){\n", " System.err.println(e);\n", " }\n", " }catch(Exception e){\n", " System.err.println(e);\n", " } \n", " return res; // should throw\n", " }\n", "\n", " public static GeoPoint closerTo(String name, Collection<GeoPoint> data){\n", " return closerTo(findByName(name), data);\n", " }\n", " public static GeoPoint closerTo(GeoPoint ref, Collection<GeoPoint> data){\n", " return closerTo(ref.latitude, ref.longitude, 1.e-50, data);\n", " }\n", "public static List<GeoPoint> read(String dataUrl) throws IOException {\n", " List<GeoPoint> res= new ArrayList<GeoPoint>();\n", " URL url= new URL(dataUrl);\n", " try(BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {\n", " String[] headers= br.readLine().split(\" \");\n", " int nbVertices= Integer.parseInt(headers[0]);\n", " int nbEdges= Integer.parseInt(headers[1]);\n", " for(int i=0; i != nbVertices; ++i){\n", " String[] coords= br.readLine().split(\" \");//latitude, longitude\n", " res.add(new GeoPoint(Double.parseDouble(coords[0]), Double.parseDouble(coords[1])));\n", " }\n", " for(int i=0; i != nbEdges; ++i){\n", " String[] data= br.readLine().split(\" \");//start end nbDirs Duration Length\n", " GeoPoint start= res.get(Integer.parseInt(data[0]));\n", " GeoPoint end= res.get(Integer.parseInt(data[1]));\n", " Integer length= Integer.parseInt(data[4]);\n", " start.neighborToDistance.put(end, length);\n", " if(data[2].equals(\"2\")){\n", " end.neighborToDistance.put(start, length);\n", " }\n", " }\n", " }catch (Exception e){\n", " System.err.println(e);\n", " }\n", " return res;\n", " }\n", " public static void main(String[] args){\n", " try{\n", " String url=\"https://raw.githubusercontent.com/jilljenn/tryalgo/master/examples/paris.txt\";\n", " data= read(url);\n", " }catch(FileNotFoundException e){\n", " System.err.println(e);\n", " }\n", " catch(IOException e){\n", " System.err.println(e);\n", " }\n", " }\n", " \n", "}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "null" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "String[] args={};\n", "GeoPoint.main(args);" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "lat:[48.8157828, 48.901557700000005], long:[2.2519666000000003, 2.3598348000000002]\n", "avg lat: 48.859211258010134, avg long: 2.338452206106807\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "double minLat= Double.MAX_VALUE;\n", "double maxLat= -Double.MAX_VALUE;\n", "double minLong= Double.MAX_VALUE;\n", "double maxLong= -Double.MAX_VALUE;\n", "double sumLat= 0.;\n", "double sumLong= 0.;\n", "for(GeoPoint p: GeoPoint.data){\n", " sumLat+= p.latitude;\n", " sumLong+= p.longitude;\n", " if(p.latitude < minLat){ minLat= p.latitude;}\n", " if(p.latitude > maxLat){ maxLat= p.latitude;}\n", " if(p.longitude < minLong){ minLong= p.longitude;}\n", " if(p.latitude > maxLong){ maxLong= p.longitude;}\n", "}\n", "System.out.println(\"lat:[\"+minLat+\", \"+maxLat+\"], long:[\"+minLong+\", \"+maxLong+\"]\");\n", "System.out.println(\"avg lat: \"+(sumLat/GeoPoint.data.size())+\", avg long: \"+(sumLong/GeoPoint.data.size()));" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6ca54079-c075-49fb-8f9c-ce09ce3dcefe", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import java.util.Arrays;\n", "import java.util.List;\n", "import java.util.ArrayList;\n", "\n", "import com.twosigma.beakerx.chart.xychart.plotitem.*;\n", "Plot map = new Plot();\n", "Rasters r= new Rasters();\n", "r.setFilePath(\"Paris.png\");\n", "r.setOpacity(Arrays.asList(new Number[]{.5}));\n", "r.setX(Arrays.asList(new Object[]{2.2519666000000003}));\n", "r.setY(Arrays.asList(new Number[]{48.901557700000005}));\n", "r.setHeight(Arrays.asList(new Number[]{48.901557700000005-48.8157828}));\n", "r.setWidth(Arrays.asList(new Number[]{2.415388-2.2519666000000003}));\n", "map.add(r);\n", " int maxIt=600;\n", "\n", "for(GeoPoint src : GeoPoint.data){\n", "if(--maxIt == 0){ break;}\n", " for(GeoPoint dest: src.neighborToDistance.keySet()){\n", " Line way= new Line();\n", " way.setX(Arrays.asList(new Object[]{src.longitude, dest.longitude}));\n", " way.setY(Arrays.asList(new Number[]{src.latitude, dest.latitude}));\n", " way.setColor(dest.neighborToDistance.keySet().contains(src)? Color.black : Color.red); \n", " map.add(way);\n", " }\n", "}\n", "\n", "return map;" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b43d5d23-563d-4f00-91c1-b4638e0f4db8", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import java.util.Arrays;\n", "import java.util.List;\n", "import java.util.ArrayList;\n", "\n", "import com.twosigma.beakerx.chart.xychart.plotitem.*;\n", "Plot map = new Plot();\n", "Rasters r= new Rasters();\n", "r.setFilePath(\"Paris.png\");\n", "r.setOpacity(Arrays.asList(new Number[]{.5}));\n", "r.setX(Arrays.asList(new Object[]{2.2519666000000003}));\n", "r.setY(Arrays.asList(new Number[]{48.901557700000005}));\n", "r.setHeight(Arrays.asList(new Number[]{48.901557700000005-48.8157828}));\n", "r.setWidth(Arrays.asList(new Number[]{2.415388-2.2519666000000003}));\n", "map.add(r);\n", "\n", "Points p= new Points();\n", "ArrayList<Object> pXs= new ArrayList<Object>();\n", "ArrayList<Number> pYs= new ArrayList<Number>();\n", "for(GeoPoint pt : GeoPoint.data){\n", " pXs.add(pt.longitude);\n", " pYs.add(pt.latitude);\n", "}\n", "p.setX(pXs);\n", "p.setY(pYs);\n", "p.setShape(ShapeType.LINECROSS);\n", "p.setSize(Arrays.asList(new Number[]{1}));\n", "map.add(p);\n", "return map;" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "87857ca8-fca6-4814-9363-14b2d04d88ef", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import java.util.Arrays;\n", "import java.util.List;\n", "String test=\"test\";\n", "Plot map = new Plot();\n", "Rasters r= new Rasters();\n", "r.setFilePath(\"Paris.png\");\n", "Object[] xs={-132};\n", " Number[] ys={56};\n", " List<Object> x=Arrays.asList(xs);\n", " List<Number> y=Arrays.asList(ys);\n", "r.setX(x);\n", "r.setY(y);\n", "Number[] hs={32};\n", "List<Number> h= Arrays.asList(hs);\n", "r.setHeight(h);\n", "Number[] ws={66};\n", "List<Number> w= Arrays.asList(ws);\n", "r.setWidth(w);\n", "map.add(r);\n", "return map;" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Today:2018-08-26T06:58+0000" ] }, "execution_count": 7, "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": {}, "outputs": [], "source": [ "import java.util.List;\n", "import java.util.ArrayList;\n", "import com.twosigma.beakerx.chart.xychart.Plot;\n", "import com.twosigma.beakerx.chart.xychart.plotitem.*;\n", "import com.twosigma.beakerx.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<Number> yList = new ArrayList<Number>();\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": null, "metadata": {}, "outputs": [], "source": [ "package test.beaker;\n", "interface DateGetter {\n", " public String getDateTxt();\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "package test.beaker;\n", "public class DG2 extends BeakerTest implements DateGetter {\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using the classpath to load a jar" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%classpath add jar ../resources/jar/BeakerXClasspathTest.jar" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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": null, "metadata": {}, "outputs": [], "source": [ "import com.beaker.BeakerXClasspathTest;\n", "\n", "BeakerXClasspathTest t = new BeakerXClasspathTest();\n", "System.out.println(com.beaker.BeakerXClasspathTest.staticTest);\n", "System.out.println(t.getObjectTest());" ] } ], "metadata": { "beakerx_kernel_parameters": {}, "kernelspec": { "display_name": "Java", "language": "java", "name": "java" }, "language_info": { "codemirror_mode": "text/x-java", "file_extension": ".java", "mimetype": "", "name": "Java", "nbconverter_exporter": "", "version": "1.8.0_152-release" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": false, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }