What Is Java? (+When to Use a Java IDE)

Bridget Poetker
Bridget Poetker  |  May 3, 2019

Think of it as the medium roast of programming languages.

A medium roast is versatile, just like Java. In fact, it was named after Java coffee (originally named Oak, then Green, and finally Java) by its creator James Gosling.

What is Java?

Similar to Python, Java is a general-purpose, object-oriented programming language that can be used across multiple platforms. The language was designed to have a similar look and feel to C++ but also to be easier to use, which is largely attributed to its level of security, compatibility across devices, and the robust nature of the code.

It’s important to note that Java and JavaScript are often mistaken for the same thing. While they use similar syntax, they are different languages entirely. Java is primarily used to build applications, while JavaScript is used to build websites.

Java is the #1 programming language, so it comes as no surprise that is used in a lot of different industries. The financial industry uses Java for transaction management in banking or writing algorithms for the stock market. The research community uses Java to better work with large amounts of data. There are many use cases for this popular programming language.

what does java look like

Why you should learn Java

As we’ve learned, Java is kind of everywhere. But, what makes it so popular? Java is relatively easy to use because its syntax is familiar that of C++. However, C++ is notoriously complex, meaning if you know C++, Java should have a much smaller learning curve.

This makes Java developers fairly versatile. The language comes with a high level of security, as it was originally built for mobile devices that move data across networks. It has the added benefit of being a cross-platform language and runs all the same regardless of operating system or device.

Java platforms

There are three different platforms developers can use to build Java mobile and/or web applications.

  • Java SE - Java Standard Edition is used to develop stand-alone apps. It provides all of the APIs needed to create desktop applications.
  • Java EE - Java Enterprise Edition gives programmers the ability to build out server-side components, allowing Java programs to work with Internet-based clients.
  • Java ME - Java Micro Edition is essentially a lite version for mobile app development.
RELATED: Learn more about the differences between web apps vs mobile apps.

Understanding Java components

The Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM) all work together to provide programmers with everything they need to build and run Java applications.

Java Development Kit (JDK)

Like a software development kit (SDK), this package is comprised of the tools and documentation required to create Java applications. It can include the JRE, an interpreter (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and more.

Java Runtime Environment (JRE)

This is the home of the program, or the place that its executed. Prior to Java (and its ability to run on any device), scripts typically used the operating system (OS) in order to run. The JRE essentially sits on top of the various operating systems to smooth over the differences between them, allowing Java to run on all platforms.

Java Virtual Machine (JVM)

This machine is a run-time engine for Java applications. In short, it manages the program’s resources.  JVM is part of the Java Runtime Environment (JRE). It contains three parts: specificiation, implementation, and instance. Using the JVM specification creates a software program, which is then called an implementation. From there, it’s released for download. The downloaded software is referred to as an instance.

TIP FOR BEGINNERS: When you download a JDK, it will include a compatible JRE, and the JRE will have default JVM. Think of a box, in a box, in a box.

Using basic Java syntax

Believe it or not, you’ll understand these terms and concepts better by actually writing the code. Let’s create and run a simple Java program. Before we start, make sure to download the latest version of Java (Java 12.0.1 as of this article’s publish date) from www.oracle.com.

Note, I’m using a Mac for this Java example. The sample code will be the same on a Windows or Linux but the applications used may vary.

Open the “TextEdit” application. From the “Format” menu, select “Make Plain Text.” Next, from the “Edit” menu, hover over “Substitutions” and make sure “Smart Quotes” is unchecked.

Keep in mind that Java is case sensitive, so follow along exactly. Type “public class HelloWorld {” on the first line and hit enter. Next, “tab” over to create an indent. Type “public static void main(String[] args) {“ on the next line and hit enter. Create a bigger indent,“tab” twice, and type the command “System.out.println(“Hello World!”);” and hit enter. Make sure it's a lowercase "L" as in line, not and uppercase "i" as in in. Indent once to close that second curly brace with “}”and hit enter, and finally just type “}” to close the first curly brace.

Java Hello World in TextEdit

We just told Java that we want to print a line that says “Hello World!” The indentations aren’t strictly required, however its good form and makes your code easier to read (e.g. the associated code visually lines up). However, each quotation and brace does need to have a pair.

Next, save your TextEdit file “HelloWorld.java” to exactly match what you called the class in the first line.

saving Java program

Now, launch the “Terminal” application. On the command line, type “cd desktop” to change the directory to desktop (where we saved the file). Now you can see that we are in the desktop directory.

changing directory for Java in Terminal

Java is what’s called a compiled language, which just means that we have to translate it before we run it (as compared to an integrated language like Python that does both at once). To compile it, type “javac HelloWorld.java” and hit enter. Nothing happens. Don’t freak out, that just means it’s done compiling it. There’s now a HelloWorld.class file now on your desktop and that means it worked.

Java compiling with javac in Terminal

It’s time to tell Java to run your program. Type “java HelloWorld” and hit enter. You should get a response back that reads “Hello World!”, just like we wrote in the code.

Java Hello World output example


Congrats! You can officially call yourself a Java developer. This Hello World Java script is obviously very basic and only uses the print command. Here are a few basic Java syntax principles to keep in mind using the above example.

  • Case sensitivity - The identifiers hello and Hello are different
  • Class names - The first letter of every word, like HelloWorld, should be uppercase
  • Method names - These should all be lowercase, such as public static void main()

When to use a Java IDE

The Terminal window we used above isn’t a traditional text editor, but it does act like one. A free text editor allows you to write code. It’s perfectly fine for beginners just starting out with Java. As you become more comfortable with the language, you should look into an integrated development environment (IDE).

This tool is very similar to the JRE explained a little further up. The main difference here is that on top of providing a space to write and run the code, Java IDEs also debug the code, and some tools include features like syntax highlighting and code completion.

Find the best Java IDE Software on the market. Explore →

Write once, run anywhere

This is the Java slogan. It speaks to Java’s cross-platform ability to run on nearly every device without having to rewrite the code.

Thirsty for more? See how Java is commonly paired with servers, databases, and frameworks to create a tech stack.

Bridget Poetker
Author

Bridget Poetker

Bridget Poetker is a senior content marketing specialist at G2, focusing on app development and design. Born and raised in the Chicago area, she graduated from the University of Illinois at Urbana-Champaign. I-L-L! In her free time, you'll find Bridget in the bleachers at Wrigley Field or posted up at the nearest rooftop patio. During the 8 months of Chicago winter, she hibernates.