We Need Java
In my previous post I discussed the differences between top-down learning and bottom-up learning — top-down and bottom-up are real academic terms taught in computer science classes, but top-down learning is kind of just something I made up to describe how we teach coding/computer science. I noticed that my college taught computer science in a very “bottom-up” way — you would learn basic syntax, you would write increasingly complex programs, and after ten weeks of C syntax you would be ready for ten weeks of C++. My roommate gave me the legitimate argument that this is foundational knowledge, but to this day I think the approach is kind of boring.
Unintentionally, I have two blogs that have developed their own kind of dichotomy: One blog goes over coding in “bottom-up fashion,” namely just to do a lot of LeetCode, and this was takes already-built things. There is a lot more to software development than just talking about/slightly tweaking existing code bases, but my real work is not open source.
tl;dr let’s use Minecraft to talk about Java.
Why Does Java Matter?
The boring answer to why Java matters is that there are 10 million Java developers in the world and the average Java developer salary in this country is $100K. A better answer is that, according to the same source, you can use Java for Android development (what about Kotlin?), web development (back end work in Spring Boot comes to mind), and Minecraft (okay, the source did not list Minecraft). A ten-second Google search also showed me that you still need Java for AP Computer Science, if you are a high school student. The honest answer is that I am tired of feeling restricted to C++, particularly on my other blog. C++ is its own universe, but in many places (including your own free time) you will find yourself working in more than one programming language.
The 30-Second Version
Everyone new to coding loves to ask what the best programming language is. Programming languages have different use cases, so it depends on what they want to do. Java is popular, easy to learn (according to them, not me), and useful in Android apps, web applications, and software tools like Eclipse…among other things.
- Java is object-oriented
- Java was modeled after C/C++ but does not use pointers…actually, there is some debate here, but for the most part you can think of Java as not having pointers, in contrast to C++
- Java has automatic garbage collection
- Java uses the Java Virtual Machine, which translates machine code to bytecode
- Java is famous for being portable, or platform independent
A JAR stands for Java ARchive, and it is a file format based on the popular ZIP format (oracle source). If you use the jar command from the command line, you can see the classes within a JAR. There are some interesting ways to modify a JAR, such as with “jar uf” or even Vim in a surprising use case, but you can also just think of a JAR as a collection of files that you are free to extract, examine, and “re-JAR”…much like a zip. Why does it matter?
Well, this is a good segue into Minecraft.
For the sake of completeness, I am going to pretend that I never heard of Minecraft until writing this blog. The 30-page paper referenced above is a pretty good illustration of the disparity between kids who play Minecraft, and the…um…completely normal adults who calculate item drop probabilities, use Lua scripts to get diamond, and sometimes lose entire weekends because the Nether has a new passive mob you can ride in lava. According to Google, Minecraft is some sort of sandbox video game that runs in Java.
I asked a friend if he had worked with JARs before, and he said his only experience was in video games. This gave me an idea. For the most part, if you are running the Java version of Minecraft, you can “abstract that part away” (unless you are running an outdated version of Java, in which case you might be hacked) and just play the game until some box asks you if you would like to update Java. You do not really have to know Java terms, like JAR or class.
Does Minecraft come with some folder I can use to easily modify a JAR? Can I write some custom Java code, repackage it, and implement some minor tweak? The answer is yes, but…um…probably not easily. Someone asked this exact question on Stackoverflow, and there were suggestions, but I think the general consensus was that this person was trying to reinvent the wheel. If you google “Minecraft mod,” you will find a slew of articles by educators attempting to use Minecraft mods to spark interest in coding.
I uncovered an entire world when I looked up Minecraft mods, and I will just scratch the surface of them here because quite a few bloggers have gotten deeper into them. Maybe in some future post, I will go deeper as well.
I may or may not have used mods myself, but I never really asked how they were made.
This is an article by BusinessInsider on how to use mods. I went ahead and followed their procedure. Below is Forge, in its open source glory. Notice that “mods” is an option.
To give you an idea what mods can do, I used to (I mean, I may or may not have) play a consolidated version called FeedTheBeast. Someone effectively built an entire universe into the game with bosses; Minecraft has two bosses, but it feels more like a sandbox than a full-on RPG.
Again, this is just surface level, but I went ahead and took the next step. According to the official Forge documentation, anyone who wants to code a custom mod can download something called the Mod Development Kit. I did so, and then I used gradle.
Here, at last, I finally opened a terminal and entered the exciting world of coding — kind of. Well technically, no.
I was using gradle, a popular build automation tool Forge chose. I was also technically using the gradle wrapper. Still not coding, of course, but building with gradle is very common in Java code bases.
I found a publicly available Gitrepo called “MineCraft By Example.” I wish they also had a YouTube channel, since it would have been nice to see the changes in action, but 1100 people starred this. The author recommended that we just have a look around.
This example shows you how to use the Forge extension “Capability”
A Capability is a way to attach information and behaviours to minecraft objects (eg Entity, ItemStack, TileEntity) at run time. It is an example of a “Decorator” design pattern link. Using Capability has a number of advantages compared to other coding methods:
It lets you easily attach information to vanilla objects, or to objects that other mods have added
Wow, this README is referring to the decorator design pattern. Anyone taking a college computer science class on software design patterns could experience it firsthand by playing Minecraft.
This code base adds additional functionality to existing/well-known Minecraft objects…namely the bow. The bow becomes a fire bow, and whatever gets hit gains a speed boost. I am not sure why they would call this “fire bow,” but the example seems instructive.
There is a lot of hatred for object-oriented programming, which definitely did not seem to be the case back when I was in school. One of the videos linked above says that Java has evolved to support the functional paradigm.
But “object-oriented” just seems like such a perfect learning metaphor to me. Minecraft is a world of imagined software objects that you can interact with. You can kill cows, extract meat, and then cook the meat. If you are not into that sort of thing, the game also has agriculture, combat mechanics, and its own construction physics.
Coding, metaphorically speaking, is the realization that you can manipulate this software world. Code forms an entire universe you can inhabit, examine, and rebuild. With Gradle, apparently.
So yes, Minecraft could be a good teaching tool for children (so long as they do not spend 100 hours staying up late to defeat the Ender Dragon).