The Idea
Have a Last-In-First-Out queue (implements java.util.Queue<E>) that will release old elements so that garbage collection (GC) can remove them. Like a cache that is a stack.
Continue reading “WeakAssQueue”Computer Programming for Humanoids
LIFO queue that will drop old elements when needed.
Have a Last-In-First-Out queue (implements java.util.Queue<E>) that will release old elements so that garbage collection (GC) can remove them. Like a cache that is a stack.
Continue reading “WeakAssQueue”I think I’ve just found a mistake in the Java Tutorial.
Maybe I’m just being pedantic, but I think I’ve just found a mistake in the Java Tutorial. It claims:
All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.
The Java™ Tutorials » Language Basics » Operators
What is this supposed to mean? Evaluation from right to left would mean that when you have a line like the following you get the rightmost expression evaluated first:
int x = 42;
x += getNumber();
// The above would be equivalent to:
x = getNumber() + x;
But that’s not how Java actually evaluates this expression. And the JLS 12 (2019-02-08) clearly states in 15.26.2 that “the value of the left-hand operand is saved and then the right-hand operand is evaluated.”
Continue reading “Java Assignments are evaluated Left to Right”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:

For beginners it is difficult to understand what a variable is. They are used in nearly all high-level languages and therefore vital for a good understanding of programming
Continue reading “What is a Variable?”Many misconceptions in Java and similar languages stem from the bad default behaviour. I’ll explain some of them.
Continue reading “Bad Defaults in Java”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.
Continue reading “Is Java easy?”The
mainmethod is similar to themainfunction in C and C++; it’s the entry point for your application and will subsequently invoke all the other methods required by your program. [Lesson: A Closer Look at the “Hello World!” Application]
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.
Many were not happy with the old API. There was Joda-Time, which later became the basis for JSR-310 and is now found in the package “java.time”.
A charset is not an encoding.
We also have StandardCharsets. It’s great to have a class with these constants. But UTF-8, UTF-16BE and UTF-16LE are all the same set of charaters: Unicode
I have my own blog on my own domain now. No more ads.
I have moved the blog from wordpress.com to my own domain. It’s on a managed server on which I run some other sites. So there are no more ads.
The new URL of this blog is:
https://humanoid-readable.claude-martin.ch
This used to be on humanoidreadable.wordpress.com. All old URLs redirect to the new blog as long as I pay them for this service.
I still have to fix some of the posts. Somehow the format of wordpress keeps changing. Now they have “blocks”, which is nice. But I have to fix all posts that contain code (that’s most of them). Until then the code will contain < instead of < and so on. But at least I now have full control and you don’t get any annoying ads.
Claude
Stalin-Sort using divide and conquer.
I just love this idea:

But when you have an input such as [42,1,2,3,4,5,6] you just get
[42] 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.
The code is on pastebin: https://pastebin.com/rEmvZSiA