10
$\begingroup$

When I start a Mathematica 8 session (either command line or with the notebook front end), I notice that there are several packages that have already been loaded for me (using SystemInformation[]):

PackagesLoaded -> {JLink`, PacletManager`, WebServices`, System`, Global`}

I understand System` and Global` and even WebServices`, but why JLink`? Does Mathematica have a primary dependency on Java? What does it use it for?

$\endgroup$

2 Answers 2

8
$\begingroup$

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@Select[
  Select[allNames,!StringMatchQ[Context[#],"JLink`"~~___]&],
  MemberQ[
    Union@Cases[
             ToExpression[#,InputForm,DownValues],
             s_Symbol/;!MatchQ[Unevaluated[s],HoldPattern[Symbol[_]]]:>Context[s],
             Infinity,
             Heads->True
    ],
    c_String/;StringMatchQ[c,"JLink`"~~___]
  ]&
]//Short[#,5]&

Out[59]//Short= {com`wolfram`documentationsearch`DocumentationSearcher`closeSearcher,
com`wolfram`documentationsearch`DocumentationSearcher`closeSearchers,
com`wolfram`documentationsearch`DocumentationSearcher`getParser,   
 <<291>>,PacletManager`Utils`Private`DumpPacletSites, Assert,SystemInformation}

And this is only in contexts that were loaded in my session, plus probably the ReadProtected functions were not searched, and I only looked at DownValues. Some of these names are names for symbols that JLink generates to map to Java classes, but others are true Mathematica functions. So, I think one can safely say that Mathematica critically depends on Java.

$\endgroup$
6
  • 1
    $\begingroup$ I should not be surprised that after I post my meager answer I see a wall of text signed Leonid above it. But I am. $\endgroup$
    – Mr.Wizard
    Jan 25, 2012 at 17:42
  • $\begingroup$ @Mr.Wizard Well, not much of a wall, this time at least :) $\endgroup$ Jan 25, 2012 at 17:44
  • $\begingroup$ The Java runtime is not installed (InstallJava[]) if there's no front end. But yes, JLink as a package is loaded. This means that when the front end connects to the kernel, it will execute some JLink-based code. Those curious could dig into some of the .tr files to find out what exactly it sends to the kernel. $\endgroup$
    – Szabolcs
    Jan 25, 2012 at 17:50
  • $\begingroup$ @Szabolcs I would not state this so definitely. Java is used in functions such as CreateArchive, Sound, various web-services functions, may be some others, all in the kernel. $\endgroup$ Jan 25, 2012 at 18:23
  • $\begingroup$ I meant that right after kernel startup, Java is not yet installed if the kernel is run without a front end, but it is if the kernel is launched from the front end. From this I conclude that the front end will use Java-dependent functions as soon as launching the kernel. I was not very clear in the original comment $\endgroup$
    – Szabolcs
    Jan 25, 2012 at 18:30
9
$\begingroup$

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 Welcome screen has a dynamic ticker at the bottom which checks for news items).

You can turn off the automatic launch by unchecking the checkbox in front of 'Automatically launch on front end startup' in the Kernel Properties dialog (which is under the Evaluation -> Kernel Configuration Options... menu).

enter image description here

Alternatively you can examine (and set) this option by looking at the $FrontEnd object:

Options[$FrontEnd,EvaluatorNames]

Which returns something like this (more if you have defined additional kernels):

{EvaluatorNames->{"Local"->{"AutoStartOnLaunch"->False}}} 

If you're really into optimizing your frontend startup time, this might be useful:

FE`Evaluate[FEPrivate`$StartTimes]//Column

Which gives an overview of the various startup stages the frontend goes through (this particular result is with the Welcome screen turned off and the kernel not automatically launching on startup). This startup time can vary widely depending on platform, kernel autolaunch settings, welcome screen visibility, auto-opening notebooks and palettes, and whether or not you have launched the frontend since your last reboot, etc):

Initializing kernel connections...->0.234
Initializing cell styles...->0.297
Initializing fonts...->0.406
Initializing menus...->0.422
Initializing defaults notebook...->0.5
Initializing defaults clipboards...->0.734
Initializing internal preferences...->0.812
Initializing kernels...->0.874
Opening Welcome Screen...->0.89
Closing Splash Screen...->0.905
Preloading Favorites...->1.03
Handling CommandLineOptions...->1.03
Opening Files...->1.03
Do Startup Action...->1.03
Finished->1.124
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.