#Java

Fix Java OutOfMemoryError

Problem: For a university project I had to implement a simple Java application that uses the Twitter4J Java library for the Twitter API to collect data (tweets) based on different criteria and then analyze those data and generate statistics. For the data analysis I used the natural language processing toolkit developed by Stanford (called Stanford CoreNLP). The problem was, that the data were too large and when running the NLP algorithms I encountered the OutOfMemoryError. Solution: increase the heap size of the Java virtual machine JVM using the flags -Xmx and -Xms. The flag Xmx specifies the maximum memory allocation pool for a (JVM), while Xms specifies the initial memory allocation pool. How to do this in Intellij? Open the "Run/Debug Configurations" of your application and in the field "VM options" add the flags -Xmx and -Xms with the desired memory amount (e.g. -Xms4g -Xmx8g).

Test simple Java RESTful Web Service

Problem: for my bachelor thesis I developed a simple Java RESTful Web Service that could be used to control a mBot robot car using the internet. For this I used a Raspberry Pi to run the web service. The Raspberry Pi was connected via USB to the mBot. The embedded mBot controls (e.g. to move forwards/backwards, spin, retreive sensor informations) were called via the internet using HTTP endpoints. Before implementing some sort of UI to map these controls to a user-friendly interface (which I later implemented as a JavaFX project) I needed to test the endpoints to see if my web service works and if the commands I implemented actually do what they are supposed to. Solution: use curl and its command line on my Windows laptop to send HTTP requests to a given URL (which is the HTTP endpoint that controls the mBot). From their webpage: curl is a tool to transfer data from or to a server, using one of the supported protocols (in my case HTTP).

Collaborate working with IntelliJ

Problem: Collaborate working with IntelliJ and Java: my colleagues and I used Java and the IntelliJ IDE for a university project (online voting system). To work together we decided to use git and had the issue, that by default the git Repository was filled with too much build data, because the .idea folder of the IntelliJ project, which contains project specific settings files and per-project details such as VCS mapping and run and debug configurations, as well as per-user details, such as currently open files, navigation history and currently selected configuration. Every commit ran into a conflict, because these files should not be commited to source control. Solution: Add a .gitignore file (also commited to the repository), which is then used by IntelliJ (and git) to determine which files and directories to ignore, before a commit is made.
Subscribe to #Java