My Books

My Software

What is Java?

Java is a powerful general-purpose programming language. That means that just about every type of program you can imagine could be done with Java. You can create desktop, web, and mobile apps with Java. In fact, many large enterprise applications are written in Java, and most Android apps are done in Java.

Java is a procedural programming language. That means that when you write Java code, you tell the computer what to do, step-by-step. (Most, but not all, programming languages are procedural.)

Java is also an object-oriented language. That means you'll structure your code in very specific ways that mimic the real world. If you're not familiar with object-oriented languages, don't worry. We'll discuss everything you need to know about that.

Java has C-like syntax; it belongs to the C/C++ family of programming languages. That means if you already know C, C++, or C#, the code you write will look and feel very familiar. If you don't know any of those, there's a good bet you'll learn one of them some day, and already knowing Java will help when it comes time for that.

Java is designed to run on a virtual machine. This has a lot of ramifications, and a full discussion is way beyond the scope of this introduction tutorial (perhaps in a later tutorial), but in short, this idea is what makes it possible for you to write a single Java program that runs on a vast assortment of operating systems and hardware without having to make changes to your code. This is what allows Java to claim one of their catchphrases, "Write once, run anywhere."

Running on a virtual machine puts it in a slightly different category than purely compiled languages (like C++ usually is) and also from purely interpreted languages (like Python usually is). Rather than your code being compiled into actual machine instructions, it's compiled into a low level language called bytecode. The final compilation step happens at runtime. That comes with a one-time performance cost on startup, but does have the advantage of allowing the final stage compiler (the Just-In-Time compiler, or JIT compiler) to know a lot about the computer it's going to be running on.

Historically, Java has been considered a slow language at runtime, but over the roughly two decades that it has been around, Java has become much faster and performance issues aren't usually a problem. Like C# it isn't usually a problem, and in the right circumstances can actually perform faster than a compiled language.

In addition, languages like Java and C# usually provide you with much faster implementation times, getting your product built faster, which is just about always more important.

Java vs. C#

C# is Java's evil twin language. (Or was Java the evil twin? I forget now.) They have a lot in common (as well as some notable differences). Generally speaking, if you know one, picking up the other is very easy.

There's history here. Java existed roughly five years before C# did. As Java started growing in popularity, Microsoft wanted to take what existed in Java and extend it in ways that they thought would be meaningful to Windows programmers. This was done in the form of a programming language called Visual J++ (mimicking the name Visual C++).

Sun Microsystems, who owned Java, didn't like what was happening and hit Microsoft with a lawsuit. Microsoft discontinued development of Visual J++, and instead decided to build a competing technology that would keep them out of legal trouble: C#.

The syntax (the way the code is actually structured and organized) of C# has a lot in common with Java, and it runs on its own virtual machine as well. While they have a lot in common with each other, they've tended to drift apart from each other over time. They are less similar today than they were originally.

At a high level, Java is a simpler language. There are fewer features to learn, which means picking the language up a bit faster and also fewer instances of reading code written by an experienced Java developer and not understanding how or why it works. The more limited feature set is an intentional design decision; the people behind Java are going out of their way to cut out features that can lead to ambiguity or confusion.

C# has a more rich set of features. Don't interpret that wrong. They are both capable of producing the same program. C# just has more ways of doing it, in theory providing you with more options so you can select the one that will be most intuitive. In short, C# has included a lot of C++ features that Java intentionally skipped over.

Another important difference between Java and C# is the breadth of target platforms. In theory, Java and C# should both be able to target virtually all computing devices, but that requires an implementation of a virtual machine for the language on all of those platforms. Java has better official coverage across all of the major platforms. C# has excellent support on Windows platforms, but only secondary support on other platforms (like Macs or Linux devices) via the open source project Mono. They do a good job, but do have a tendency to run a bit behind Microsoft versions.