El blog de Juan Palómez

28 noviembre 2017

Yet another Why Java Sucks article

Filed under: Java, programming, software development — thisisoneball @ 16:34

Many Java developers/users have their own list of things that suck about Java, so here is mine (there are a lot more, the list is a work in progress). Of course there are many positive things as well, but I’ll leave that for another article:

(if this list doesn’t look up-to-date to you, make sure to read the note below)

As a developer:

  • has String.split() but no String.join() 😮
  • has no one-line function like, e.g. String[] ocurrences = String.match(sourceString, “/regex/”)
  • has no concept of CWD (current working directory)
  • has no range function or operator (like Python range() or Perl and Shell “..” operator)
  • has nothing like b[] = map(myFunction, a[]), which returns in b[] the result of applying myFunction to every element of  a[] (like Lisp’s map() function or Python’s map() function)
  • extremely verbose and repetitive as opposed to simple and concise
  • no unsigned integer types
  • everything is and object, except when it isn’t (e.g. even the boolean native type and the Boolean class are so different that one of them allows for three-valued logic and the other doesn’t!)
  • not so platform-independent, even within the same operating system (e.g. Windows) there is usually a JRE-hell in terms of version number and 32/64 bit versions — also affecting users

As as user:

  • bulkier and slower applications than native ones, requiring more RAM — also affects developers when testing
  • look and feel that doesn’t match the Window Manager of the OS or Desktop Environment


Note: some of these may be already added to the language, but if they are still listed here is because they were added unreasonably late, i.e. when every other popular language had it. That meant:

  • wasting time looking elsewhere for a library or coding it yourself (reinventing the wheel)
  • adding overhead in terms of third-party JARs for maybe just one or two functions
  • causing fragmentation (different developers in the team using different third-party JARs for the same thing)

Let’s say those missing features were added in Java 8 (2014 !!) … that’s so late that developers are already using the other approaches, and will probably keep using them, so the overhead, fragmentation, etc. will stay there. Also, users may have an older JVM installed (e.g. Java 7 is still the one installed on many PCs in 2017) so either your application won’t work on their systems, or you’ll have to go back to code in the previous version and lose the “new” features



5 febrero 2017

Generic POI troubleshooting

Filed under: Java, POI, programming, xlsx — thisisoneball @ 20:45

This is a compilation of things you can check in case you’re having trouble using POI in your Java program, particularly when creating .xlsx files:

  • Slow execution or program crashes with “Could not reserve enough space for object heap” , “java.lang.OutOfMemoryError: Java heap space”, or similar:
    • increase heap size (e.g. -Xmx1000m), for sizes bigger than ~1500MB you must use a 64bit JVM
    • monitor the output of freeMemory() in different parts of your program or inside loops and see the evolution
    • make sure you free up POI objects when no longer used
    • use File objects and not Stream objects for POI stuff, for example for reading your input .xlsx files
    • if allowed by your requirements, split the output into multiple .xlsx files instead of a single file containing multiple tabs
    • make sure you are not creating a style for each cell, for each needed style create just one and apply to multiple cells (*)
    • run program with  -XX:+HeapDumpOnOutOfMemoryError, on crash it will create a big .hprof file, open it with Eclipse MAT (or similar program) and analyze which objects are taking up more resources
    • try a different POI version. You can verify which version is being used at runtime with Workbook.class.getProtectionDomain().getCodeSource().getLocation().getPath()
    • try with both 32bit and 64bit JVM
    • if allowed by your requirements, try with both HSSF and XSSF. Also SXSSF is the most lightweight of the 3, but also has less features
  • Execution is OK but Excel says the generated .xlsx file is corrupt/invalid
    • combined/merged cells may be overlapping. This could be detected at runtime, if not, open the generated .xlsx file as a ZIP file and check the files to see which are the overlapping cells
    • the styles.xml file inside the .xlsx file is not valid or too big, check (*)

Crea un blog o un sitio web gratuitos con WordPress.com.