Hot answers tagged

24

I've implemented a java program using the JavaMail API to only fetch unread emails from a particular user (and mark it as read). This will allow you to periodically get emails from your ship traffic service. This is inspired by this blog post on Stephen Wolfram's email analytics. 1. Java code to fetch unread email from a sender Below is the java code, ...


18

Note that ListContourPlot3D takes the coordinates to be the position indices by default. If you want to keep the coordinates used in generating the data, then you have to include it. data = Flatten[ Table[{x, y, z, x^2 + y^2 + z^2 + RandomReal[0.1]}, {x, -2, 2, 0.2}, {y, -2, 2, 0.2}, {z, -2, 2, 0.2}], 2]; plot = ListContourPlot3D[data, Contours -&...


15

Here is a more general approach. It is based on the 2D method from here. It assumes the polyhedron is not self-intersecting but imposes no requirement of convexity or even connectedness, other than that it be closed and bounded. Strictly speaking, I think this will work for an unbounded polyhedron provided it contains no vertical ray. For ease of exposition ...


15

Along the lines of Yamareth's answer, but probably an even better technique, is to put the following into $UserBaseDirectory/Kernel/init.m: Needs["JLink`"] SetOptions[InstallJava, JVMArguments->"-Xmx32g"] SetOptions[ReinstallJava, JVMArguments->"-Xmx32g"] ReinstallJava[] By setting the default options, you will get the desired heap size any time you ...


14

To call Mathematica from Clojure, you will want to use Clojure's Java interop to access the Wolfram JLink classes to script Mathematica access. Start by launching Clojure with a classpath that includes the JLink.jar, for example with this batch file: @echo off set MATHEMATICA=C:/M/9.0 set JLINKJAR=%MATHEMATICA%/SystemFiles/Links/JLink/JLink.jar java -cp C:/...


13

The following guide shows how to conduct communication between nanohttpd, an http server for Java, and Mathematica. The result is a server that, if you go to its address in a web browser, displays the result of SessionTime[], i.e. the time since the Mathematica kernel associated to the server started. I'm going to write as if the reader was using OS X with ...


12

What you did with setting the "com.wolfram.jlink.libdir" property will work. Perhaps you didn't enter the correct path, or you used the wrong JLinkNativeLibrary.dll file (meaning you used the 32-bit one from JLink/SystemFiles/Libraries/Windows, instead of the 64-bit one from JLink/SystemFiles/Libraries/Windows-x86-64, or vice-versa). But you really shouldn'...


12

We can start by creating the parts using the same code as the question: partSource = JavaNew[ "org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource", "mmagraphics.png", MakeJavaObject["abcdefg"]@toCharArray[]]; part1 = JavaNew[ "org.apache.commons.httpclient.methods.multipart.FilePart", "filename", partSource]; ...


12

I am writing this answer for a person who is familiar with Mathematica and has a good understanding of computer programming, but not so familiar with Java programming language. Using GraphStream is not so different from using any other Java library. You need to download the GraphStream core files from here and extract it. gs-core-1.1.2.jar is the only file ...


11

Comment I've placed a Notebook version of this post on my webspace here: http://facstaff.unca.edu/mcmcclur/polylineDecoder.zip The Notebook is actually contained in a ZIP file that also contains all the Java class files necessary to get this code to work. The Notebook sets the Java class relative to it's own directory using AddToClassPath[...


11

Here is a fast method that will "often" work. Roughly, it requires that the convex polygon have no sharp angles between faces. Preprocessing goes as follows. Create triangles from the polygons. So a 5-gon with vertices {a,b,c,d,e} would become the set of triangles {{a,b,c},{a,c,d},{a,d,e}}. For each vertex we average it's star (set of points connected by ...


11

Nice answer by Mohsen, +1. I am continually impressed by the quality of the J/Link and .NET/Link expertise on this site. I have a couple remarks and then an example program. The question asked about some general tips for getting started with J/Link. This GraphStream library provides a perfect example for the typical workflow of a J/Link project. The ...


10

Preamble In fact, the relevant example can be found in the documentation, here, in the "Sample program" section. To make this useful also for folks who don't have experience with Java development in WorkBench, I will illustrate how this can be done from within Mathematica, by using the interactive Java reloader from this post. You will have to figure out ...


10

This is an issue with XOWA. The HTTP Server was rewritten in v2.7.2 to handle POSTs and other features. However, it looks like it crashes on your request. I'll look at fixing this for v2.8.2. I'll comment again here when I have a resolution, but feel free to contact me directly for more info. Hope this helps! [Edit: This was fixed for v2.8.2. XOWA now ...


9

By default the frontend will automatically launch the kernel; this is just a preference setting for the default 'Local' kernel. It's on by default since at one point or another, a user is likely going to want to start a kernel to do computations with Mathematica, and even if not, there are many services in the frontend which require the kernel (even the ...


9

Enumeration value names are accessible using LoadJavaClass to load the enum class. However, this particular case is complicated by the fact that the enum class Form is an inner member of the class Normalizer. To load it, we must reference Form by its so-called binary name: LoadJavaClass["java.text.Normalizer$Form"]; Now we can reference the enum values ...


9

One problem is that your path to javaw is wrong (you forgot the bin dir). But that quoting style is very hard to make work, and possibly flat-out wrong (I swear that example in the documentation worked about nine years ago when I wrote it, but I cannot seem to make anything like it work now; my apologies). The correct way is to invert your single and double ...


9

There are two parts to accessing the contents of a Java Map object. The first is to traverse the iterator interface to extract the map elements. The second is to use accessor methods on those elements to extract their properties. For the purpose of discussion, let's create a map from strings to Java date objects: Needs["JLink`"] InstallJava[]; $map = ...


8

As far as I know, JLink is used at least in PacletManager`, for operations like loading data on demand etc. The documentation system also uses Java. Perhaps, other uses as well. I don't think that Java is used a lot for the core language though. This code can make it a bit more quantitative: allNames = Flatten[Names[#<>"*"]&/@Contexts[]]; Quiet@...


8

In Version 10 we have BoundaryDiscretizeGraphics and RegionMember to the rescue. So here we go: Reproducing the graphics: data = Flatten[Table[{x, y, z, x^2 + y^2 + z^2 + RandomReal[0.1]}, {x, -2, 2, 0.2}, {y, -2, 2, 0.2}, {z, -2, 2, 0.2}], 2]; (* Thanks to Taliesin Beynon for the tip *) plot = ListContourPlot3D[data, Contours -> {1}, Mesh -> None,...


8

I was able to get a satisfactory answer to my question by using a very good article by David Wagner, "MathLink Mode" available here. I'll leave all the JVM stuff out of the answer but the approach does work just as well for a kernel launched by some external program as it does for the direct launch explained here. I'll explain it for Windows but there isn'...


8

Here's a minimal example using the Java API of IB. Anything else can be done in theory by analogy. It works in Windows, but should work on other platforms as well as it's using Java. Results are displayed in the Mathematica messages window. Prerequisite Read the beginning of https://www.interactivebrokers.com/download/JavaAPIGettingStarted.pdf , download ...


8

The solution After a standard initialization step Needs["JLink`"] InstallJava[] What you have to do is actually very simple: arr = MakeJavaObject[{1,2,3}] (* « JavaObject[[I]» *) You can test that the object contains your data: JavaObjectToExpression[arr] (* {1, 2, 3} *) Let's test for large array: (lrg = MakeJavaObject[Range[1000000]])//...


8

Minimal code Here is a minimal code (partly adopted from RLink), to get you started. First, load JLink: Needs["JLink`"] InstallJava[] Here is the code: ClearAll[logIt]; logIt[logger_,msg_String,mode_String]:= Block[{trace, debug, info, warn, error, fatal}, With[{ method = mode /. { "TRACE" -> trace, "DEBUG" -> debug, ...


7

I also encountered this problem. Not an authoritative answer, but here is one blind guess to what is happening. JLink has its own classloader, JLinkClassLoader.java, which calls another one, JLinkClassLoaderHelper.java. The latter is a sub-class of URLClassLoader.java. Both are used in the class JLinkSystemClassLoader.java. The second part of this story is ...


7

You don't need JLink for this, because MINE program (Java version) seems to not be able to transmit the results by any data transfer protocol. Rather, you launch it from the command line, as a Java executable (jar file). It takes the name of the input data file as one of the command line parameters, and it writes its output into another file. I will ...


7

A few ideas: If it's a package that is to be used regularly, I'd put it in one of the standard locations where M searches for packages, such as e.g. $UserBaseDirectory/Applications. SetDirectory doesn't affect the search locations for packages. SetDirectory sets what's called the "working directory", while Get searches only those locations which are ...


7

For your first question you can look at the customer stories in finance and analytics. You might also be interested in the recordings from the Wolfram Finance Platform virtual workshop.


7

As of Mathematica v10, SQLite seems officially supported (at least on OS X): Needs["DatabaseLink`"] Select[JDBCDriverNames[], StringMatchQ[#, ___ ~~ "SQLite" ~~ ___] &] (* {"SQLite", "SQLite(Memory)"} -> not in v9, new in v10! *) Testing with the Chinook example database: conn = OpenSQLConnection[JDBC["SQLite", "/Users/username/Downloads/...



Only top voted, non community-wiki answers of a minimum length are eligible