With Windows Subsystem for Linux (WSL) we can now use Linux tools, such as grep, rsync, ssh, and network commands, such as dig and netstat, on Windows directly. No need for cygwin or other 3rd party software.
Here’s an example on how uname is unknown to Windows, but WSL (Ubuntu in my case) knows it:
So when writing Java programs you might want to use this feature. There really isn’t much to say about this because youcan just easily use it. But note that WSL probably uses UTF-8 (as most linux systems are using UTF-8) while CMD /U uses UTF-16LE .
I assume you will need 64bit Java. There’s probably a way to run WSL (which is 64bit) from a 32bit executable. But it’s 2019 and I see no reason to run 32bit Java.
Often you run a simple command that returns a single line, such as which or uname. So my function returns a List of Strings, so you can easily get the first line:
Java isn’t easy. It’s often more complex than needed. But being easy for beginners shouldn’t be a design goal with high priority.
Should a programming language be easy?
I don’t know why so many educational establishments use Java to teach programming. They often start with Java in the first semester. Even the Oracle tutorials expect the reader to already know some basics. Java was designed for programmers who already know C/C++ as seen in this example.
Was 1900 a leap year and does every minute have 60 seconds?
In Java we have a new API for Date and Time since Java SE 8. Before that, there was already an API with mutable dates and fore some reason there was a date just for SQL. Since many were not happy with it there was Joda-Time, which later became the basis for JSR-310 and is now found in the package “java.time”.
But when you have an input such as [42,1,2,3,4,5,6] you just get  instead of [1,2,3,4,5,6]. You can get a better result if you use divide and conquer. And that is something Stalin would do, don’t you think? So I implemented a recursive solution in Java. It tries all possible results, which is not a single pass and therefore defeats the purpose of having a fast O(n) algorithm. And my implementation isn’t even in-place. A new data structure has to be created. That’s why I also added an implementation using a linked list, which is what Mathew describes.
Java (both the language and the JVM) are not aware of constants. To reduce confusion it’s better to not use the term “constant” in Java code, unless it’s actually a universal constant. Continue reading “Java knows no Constants”