What is Programming and Why Java?

Jack Boyuan Xu
4 min readDec 29, 2019

--

Java, but it’s not the coffee we are going to learn.

What is Programming?

Programming may seem like some witchcraft but I guarantee you it isn’t.

As humans, we write essays every single day. Text messages and speech are essays too — just not the long ones that we have all come to dread as students. We write essays to inform each other of our intentions, tell others what to do, and in general, communicate. Programming is exactly the same in this aspect but we write it to computers instead. Take a moment and think about it: all programs are made with an intention in mind, even if it’s to waste your time and drain your wallet. Behind those intentions are humans. Computer programs are simply essays that humans write to computers so the computers can behave as we wish. However, because computers are cold and perfectly logical machines, our essays also have to be written in a special language that computers can understand with sound logic. That is precisely what makes programming seem so difficult and in some cases, it really is as hard as it seems. We not only have to learn the language, but also be logical in our way of thinking. If our logic is not sound, the programs we write will also malfunction. When a program that you write doesn’t behave and you get the urge to curse, “why the hell don’t you work”, take a moment and think about it: you are essentially saying, “why the hell am I so daft that I can’t even let the computer do what I want.”

We will be learning Java to begin with.

Why Java?

Java is an exceptionally versatile language. Originally developed by Sun Microsystems and now Oracle, it is one of the most widely used languages out there. The reason Java is so popular is due to its platform agnostic nature, meaning you only have to write the code once and it will be able to run on any platform that has a standard implementation of the Java Virtual Machine (JVM).

What is the JVM you ask? It is a program that creates another “fake”, or virtual, computer that runs on top of your physical computer. It provides a common platform and creates a standard environment regardless of the host environment. For example, the JVM for macOS, Windows, and Linux are all implemented differently because their host operating systems are different. However, the virtual environment they create that programs written in Java depend on is standard so that a Java program written in Windows can also be run on macOS or Linux because it isn’t your actual computer running the Java program, it’s the JVM (this is a simplification). Think of the JVM as different kinds of tripod mounts: every camera requires a different kind tripod mount, but the mount itself has a standard that enables different cameras to be put onto the same tripod. In this case, the different cameras are different operating systems and the tripod is your Java program.

To get a bit more technical (and bear with me here), normally a program written in a compiled language such as C++ is compiled (made from a bunch of source code into an executable that can be run) into native machine code directly. Machine code, as the name suggests, communicates directly with the operating system and the underlying hardware without any intermediaries. The great advantage of native machine code is performance, mostly due to its lack of intermediaries. The drawback, however, is that there needs to be a separate version of the same program compiled for different operating systems (Windows, macOS, Linux, etc.) because all of them are different. Sometimes the program itself even needs to be altered in order to interact with different operating systems. Java solves this platform issue with the JVM, as we talked about previously. The compiled Java bytecode cannot be understood by the machine directly but it is understood/interpreted by the JVM. The JVM then translates those actions into instructions that the host system can understand and execute. Java is what’s called an interpreted language**. Python is another example. However, since we’ve added a middle layer into the mix, performance of interpreted languages is inferior to compiled languages. Fortunately, processors nowadays have become so fast that the performance loss is mostly negligible.

A Java program, from source code to execution.

** Java isn’t really an interpreted language as the source code is indeed compiled into bytecode. But it isn’t a compiled language because machines cannot run bytecode directly. We’ll just say it’s an interpreted language for now, but keep this in mind. (In addition, the JVM is clever and uses a Just-In-Time/JIT compiler at runtime to boost performance, but we won’t cover that here.)

If you have an Android device, you are already familiar with what Java can build: Yes, the Android OS is built on a Linux kernel running a virtual machine that eventually runs applications written in Java (Kotlin and native C++ are also available but we won’t talk about those).

Java is also a good middle ground for beginners. It is explicitly typed, meaning greatly reduced ambiguity and promotion of good programming practices compared to JavaScript (which has absolutely nothing to do with Java besides the name). Its syntax is relatively simple compared to C++. Due to its interpreted nature, its setup is universal across all platforms. Most importantly, I have already made plenty of videos regarding Java for CSCI-201 at USC. Not only more resources are available to you, I also get the chance to further expand and compliment my existing material. Win-win!

In the next article, we will finally start to do actual work. Stay tuned!

--

--

Jack Boyuan Xu

Co-founder & Tech Lead @ EthSign. Blockchain Lecturer @ USC.