Choosing Java as your language for a Machine Learning project - Are we crazy???
Tags: java, chatbot, machinelearning, language
Published: 2021-11-04 11:13:26

Most people are stunned when they realize that the <a href="https://github.com/xatkit-bot-platform" target="_blank" rel="noopener" data-schema-attribute="">Xatkit bot engine is written in Java.</a> 

True, the vast majority of AI / Machine Learning projects are written in Python. But this doesn't mean that you should go with Python when starting your own project. And don't worry, this is <strong>not a post about language wars</strong>. I don't pretend to say that Java is better than Python (nor the other way round, for that matter). I'm just explaining our language choice. And suggesting that you should take into account many aspects when choosing the base language for your next project.

Let's see why Java is a good choice for Machine Learning projects, or at least as good as a choice as many others:

<ul>
 	<li dir="auto"><strong>Machine Learning is only a small part of your project</strong>. Most of your code will NOT be about ML tasks but about data input/output, user interface, interaction with external services,... so the language needs to be good at all these things as well.  This is <a href="https://xatkit.com/the-software-challenges-of-building-smart-chatbots/" target="_blank" rel="noopener" data-schema-attribute="">especially true in the case of chatbots</a> that, to begin with, need to interact with different user input platforms.</li>
 	<li dir="auto"><strong>There are ML libraries available for every language</strong>. So there is always a way to execute/train your neural networks outside the python world. For instance, in Xatkit, we reuse <a href="https://stanfordnlp.github.io/CoreNLP/usage.html" target="_blank" rel="noopener" data-schema-attribute="">Stanfords' Core NLP</a> models in some of our <a href="https://github.com/xatkit-bot-platform/xatkit/wiki/Processors" target="_blank" rel="noopener" data-schema-attribute="">language processors</a>. And, if needed, there is always the option to wrap the ML models code in a Python server (I like the simplicity of <a href="https://palletsprojects.com/p/flask/" target="_blank" rel="noopener" data-schema-attribute="">Flask</a> for this) and consume them via API calls to this server.</li>
 	<li dir="auto"><strong>Java is heavily used in the enterprise world</strong>. So while core ML fans may frown at our language choice, enterprise users may see Java as a benefit as they already know how to manage and deploy Java-based applications but they could not have the same experience with Python or other languages.</li>
 	<li dir="auto"><strong>We are Java "experts"</strong>. We are much more productive coding in Java than with any other language. Of course, we could become proficient in Python if we put the time but time is precious and it made sense to stick to the language we were already using in other projects</li>
 	<li dir="auto"><strong>Xatkit is a model-based tool. </strong>By model, I refer here to <a href="https://modeling-languages.com/clarifying-concepts-mbe-vs-mde-vs-mdd-vs-mda/" target="_blank" rel="noopener" data-schema-attribute="">software design models</a>, not ML ones. An in the modeling ecosystem, Java is still the boss. In particular, Xatkit reuses some <a href="https://www.eclipse.org/modeling/emf/" target="_blank" rel="noopener" data-schema-attribute="">EMF</a> libraries, mostly to do some reflection on the bot definition at runtime. For sure, there are other ways to accomplish the same goal, but you can see this as a legacy decision before <a href="https://xatkit.com/fluent-interface-building-chatbots-bots/" target="_blank" rel="noopener" data-schema-attribute="">Xatkit embraced Fluent APIs</a> for the bot definition.</li>
</ul>
As you can see, maybe Java should not be your first option when getting started in AI technologies if there is <em>really</em> no constraint at all on your language choice. Otherwise, the choice of a language is more of a social/team/organization decision that should take into account many other aspects (team knowledge, organization architecture, integration needs,...). We see developers arguing non-stop about why language A is better than language B but for most projects, even those including some kind of intelligent component, any major language will work and that choice will NOT be the core element in the project success at all.

So, forgive me if [we](https://xatkit.com/) continue developing bots in Java :-)