The Java Programming Language
Early in the history of computer programming, resources were incredibly tight.
Computers weren't capable of keeping track of much information at all, and it
became necessary to efficiently use every bit of programming power that computers
had. At the same time, we needed to make that power accessible for humans who
write the programs that make it all work.
In 1995, Sun Microsystems released the Java programming language to tackle these
issues. Since then, Java has been known for being simple, portable, secure, and
robust. Though it was released over twenty years ago, Java remains one of the most
popular programming languages today. Due to its innovative use of a built-in
compiler, Java code can be run on different operating systems and platforms.
Indeed, Sun Microsystems’ slogan for Java was, and largely still is, “write once, run
everywhere”.
As stated earlier in the course, more than 10,000 companies use Java somewhere in
their stack today, and that's why we're going to start by learning about it first.
#Welcome to the world of Java Programming!
As a developer, you will write Java programs. The code that you write will then be
passed into a compiler, which will hand off that code to what's known as a Java
Virtual Machine (JVM). The JVM's job is to act like a universal translator, making your
code available to any operating system that tries to run it, such as Windows,
MacOS, and Linux:
Java programs are passed into a compiler, which then uses a JVM to get that code running on modern
operating systems.
This compilation is why Java is still so useful today. When programs are written to
run on Windows, they generally won't be able to run MacOS or Linux. This is true of
many high-level languages–the ones that we developers write–because they're
usually designed for a specific operating system. When we run a program, the OS
does the work of translating that higher-level language down into a lower-level
language, which eventually leads to the ones and zeroes that the hardware needs to
do its job. With Java, we can write our code wherever we need to because it will be
compiled for us. This makes Java a "Platform Independent Language".
#What is the Java Virtual Machine?
The JVM (Java Virtual Machine) is an abstract machine that enables your computer to
run a Java program. The computer you're using to view this page is a physical
machine running software that has produced this page. You can think of virtual
machines as being implementations of software designed to run like hardware, but
in a way that allows one set of hardware to run many different machines for many
different purposes.
When you run a Java program, the Java compiler first compiles your Java code into
an intermediate step called bytecode. Bytecode is essentially a quick stopover–one
that doesn't depend upon the OS, and can easily be translated out to whatever
language it needs to be. From here, the JVM translates that bytecode into native
machine code, a specific set of instructions that a computer's CPU can execute
directly.
Java is a platform-independent language because when you write Java code, it's
ultimately written for the JVM, not for your physical machine. Since the JVM executes
this platform-independent Java bytecode, anything you write in Java can be run on
any system that wants to run it.
How a Java Program works: from developer to user
#Zooming Out from the JVM
The JVM is just one piece of a larger puzzle when it comes to Java delivery pipeline.
Let's keep zooming out for a moment and see what else is required to get a program
up and running on a user's computer.
#The Java Runtime Environment
The Java Runtime Environment (JRE) is a software package that provides a bunch of
useful tools that we'll be using to get our Java programs running. This includes Java
class libraries, the aforementioned Java Virtual Machine (JVM), and other
components that are required to run Java applications.
You can think of the JRE as a container that holds the JVM.
The JRE is a runtime environment that contains our JVM and some helpful class libraries.
If you only need to run Java programs, but you don't need to develop them, the JRE
is all you need.
#Java Development Kit
The Java Development Kit (JDK) is a software development kit required to develop
applications in Java. When you download a JDK, the JRE described above will be
included in that installation.
In addition to the JRE, the JDK also contains a number of development tools, like
compilers, JavaDoc for documentation purposes, a Java Debugger, and a few other
tools:
The JDK contains our JRE, plus some helpful tools for making sure that our application runs as planned.
#When You Put It All Together:
All together, this is what the JDK ends up looking like:
The Java Development Kit all in one image.
#The Basics: Java and OOP
Now that you understand how a Java program gets from the developer's keyboard
through to the user's screen, we should talk briefly about how we write Java
programs: object-oriented programming (OOP). There are many different ways of
programming, but Java adheres to the OOP paradigm. In OOP, we write our code to
create objects which contain code including variables and methods that they use to
interact with other objects.
For now, let's use a metaphor: think of objects as Lego bricks. Each brick will have its
own specific size and shape, and it can be combined with other bricks to create
larger structures. Some Legos will be more complex than simply interlocking with
other bricks–like having axels, wheels, or hinges–but none of them is particularly
impressive alone. It is only when they come together that they can create something
truly spectacular.
A pile of Legos, care of Nick Nice on Unsplash
Every object in OOP has a purpose to fulfill, but each one is a separate entity that can
be detached from the program as a whole. OOP, therefore, represents a modular
design paradigm where individual entities come together to create complex
programs capable of nearly anything you can imagine a computer doing.
#Summary
These are the basics that make Java work, but remember: this lesson is just a primer
to launch us into writing a bit of code ourselves. We'll dive much deeper into each of
these pieces as we progress through the curriculum, so don't worry about
researching the above for hours on your own. We'll get there.
#Extra Resources
If you'd like more information about how a platform-independent language works,
check out this quick two minute video:
https://youtu.be/wsAbhPQKHvo
Back
Unsubmit
Next