Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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.

share|improve this answer
    
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. –  Mr.Wizard Jan 25 '12 at 17:42
    
@Mr.Wizard Well, not much of a wall, this time at least :) –  Leonid Shifrin Jan 25 '12 at 17:44
    
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. –  Szabolcs Jan 25 '12 at 17:50
    
@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. –  Leonid Shifrin Jan 25 '12 at 18:23
    
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 –  Szabolcs Jan 25 '12 at 18:30
show 1 more comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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