What is Java?

In the last lesson you got your first look at Java. You hear the name everywhere: Android apps, banks, job posts. So what is Java, really? Let’s clear that up before we write any code.

☕ What is Java?

Java is a programming language, a way to write instructions a computer can follow.

  • The computer only understands 1s and 0s. You cannot write in that.
  • So you write Java, which reads close to English. A tool translates it into 1s and 0s for you.
  • Java is one of the most popular of these in-between languages.

What makes Java, Java:

  • High-level. You write in near-English words, so you focus on the idea, not the hardware.
  • Object-oriented. You build your program from small pieces called objects, each holding some data and some actions. More on this later.
  • Strongly typed. You label each box with the kind of value it holds, like a whole number or text. Try to put text in a number box and Java stops you on the spot, so mistakes get caught early.
  • Runs almost everywhere. The same program runs on Windows, Mac, Linux, phones, and servers with no rewrite.

🤔 Why was Java created?

Before Java, code written for one computer often would not run on another:

  • The pain: Riya writes a video player for Windows. The boss now wants it on Mac and Linux too.
  • The old way meant rebuilding big parts for each one. Three machines, three painful rebuilds, three copies to keep in sync.
  • Java’s answer (1990s): Write Once, Run Anywhere. Write the program one time and it runs on any machine that has Java installed, no rewrite.

That one idea is why Java spread so fast and is still everywhere. Riya writes her player once and it runs on all three machines.

🌍 Where is Java actually used?

Java runs real products millions of people use every day:

Area What people build with Java Real example
Android apps The logic behind mobile apps Many apps on your phone
Banking and finance Systems that move money safely Bank back ends, payment systems
Big company back ends Servers that handle huge traffic Netflix, Amazon, Uber services
Big data tools Software that crunches huge data sets Apache Hadoop, Apache Kafka

Notice the pattern. Java gets the jobs where you cannot fail:

  • Tap “pay” in a banking app and that money must move correctly every time.
  • Millions open Netflix at 8pm and the servers must not crash.
  • Java is steady under that pressure, so people running serious systems keep choosing it. That makes it a safe bet for a career.

🧩 A first look at Java code

Here is the classic first program. It prints “Hello, World!” on the screen.

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

What each part does:

  • public class HelloWorld starts a class, a container that holds your code. Every Java program lives inside one.
  • public static void main(String[] args) is the main method, the starting point. Java looks for main and begins there.
  • System.out.println("Hello, World!") does the work. It prints the text in quotes to the screen. println means “print this line”.
  • The curly braces { } mark where each block begins and ends. The inner block belongs to main, the outer to the class.

When you run it:

Output

Hello, World!

That is a lot of words to print one line, and that is normal for Java. The extra structure feels heavy at first, but it is also why Java stays steady on big projects.

Here is a second example. It greets a person by name and adds a message:

public class Greeting {
public static void main(String[] args) {
String name = "Alex";
System.out.println("Hello, " + name + "!");
System.out.println("Welcome to Java.");
}
}

The new parts:

  • String name = "Alex"; makes a box called name holding the text Alex. String is Java’s word for text.
  • "Hello, " + name + "!" glues pieces of text together, so you get Hello, Alex!.
  • The second println runs right after the first. Java reads your lines top to bottom.

When you run this:

Output

Hello, Alex!
Welcome to Java.

The program is no longer fixed. Change "Alex" to "Riya" and the greeting changes too. You store a value, then use it. That is your first taste of real code.

⚙️ How does Java actually run?

This is the secret behind “write once, run anywhere”. Other languages turn your code straight into instructions for one type of computer. Java does something smarter:

  • You write .java files. Your code in plain text, the kind you saw above.
  • The compiler turns it into bytecode. The Java compiler reads your code and produces bytecode, a halfway form made not for one machine but for the Java machine.
  • The JVM runs the bytecode. The Java Virtual Machine (JVM) is a small program sitting on top of your computer. It reads the bytecode and runs it on whatever machine you are on.

Why this matters:

  • Every kind of computer has its own JVM. Windows has one, Mac has one, Linux has one.
  • Your bytecode stays the same. Each machine’s JVM fits it to that machine. That is how one program runs everywhere.
  • No JVM installed means your Java program will not run there. The JVM is free and runs on almost everything, so this is rarely a problem.

One line to remember

You write Java code once. The compiler turns it into bytecode. The JVM on each computer runs that same bytecode. That is the whole “Write Once, Run Anywhere” trick.

📜 History of Java

Java was born at Sun Microsystems, started by a team led by James Gosling in the early 1990s. They wanted one language that could run on many machines:

  • It began as a side project in 1991, first named “Oak” after a tree outside the office.
  • It was renamed Java and released in 1995.
  • The promise from day one: write once, run anywhere.
  • Sun Microsystems later joined Oracle, so today Oracle owns Java.

Java is old, tested, and trusted. When a language has run banks and phones for decades, you know it works.

✨ Features of Java

Java spread so far because of the mix of things it does well:

  • Platform independent. Your code becomes bytecode, and the JVM runs that same bytecode on any machine.
  • Object-oriented. You build your program from small parts called objects, which keeps big programs neat and easy to grow.
  • Simple. Java dropped many tricky parts of older languages, so it is easier to read and learn.
  • Secure. Your code runs inside the JVM, which acts like a safe box. One reason banks trust it.
  • Robust. Java catches many mistakes early and handles errors well, so programs rarely crash.
  • Multithreaded. Java does many things at once, like serving thousands of users without slowing down.
  • Automatic memory management. Java cleans up memory you no longer need on its own, so you make fewer mistakes.

Each one points back to the same goal. Java wants to be steady, safe, and able to run anywhere.

⚠️ Common Mistakes

A few small things trip up almost everyone in week one. Here they are as wrong versus right.

The class name and the file name must match. If your class is HelloWorld, the file has to be HelloWorld.java.

// ❌ Wrong: class is HelloWorld but file is saved as hello.java
public class HelloWorld { }
// ✅ Right: class HelloWorld lives in a file named HelloWorld.java
public class HelloWorld { }

Every statement inside a method ends with a semicolon. Forget it and Java stops with an error.

// ❌ Wrong: no semicolon at the end
System.out.println("Hello")
// ✅ Right: semicolon closes the statement
System.out.println("Hello");

Java cares about capital letters. System is not the same as system. And Println is not the same as println.

// ❌ Wrong: lowercase s, capital P
system.out.Println("Hi");
// ✅ Right: exact spelling and case
System.out.println("Hi");

When an early error pops up, check these first: a wrong file name, a missing semicolon, a wrong capital letter. They cover most beginner errors.

✅ Best Practices

A few simple habits make your Java life easier from day one:

  • Name your class clearly. A class that greets people is a better Greeting than a vague Test1. Good names tell the reader what the code does.
  • Keep one public class per file, with the file name matching it. This is what Java expects and keeps your project tidy.
  • Indent the code inside braces. Lines inside main sit a few spaces in. That spacing shows what belongs inside what.
  • Run your code often. Write a little, run it, then add more. Small steps mean small, easy-to-fix mistakes.

This is all about staying clear. Clear code is code you can come back to next month and still understand.

⚠️ Common Myths About Java

A few things repeated online confuse people just starting out:

  • “Java is the same as JavaScript.” No, two different languages with similar names, like “car” and “carpet”. Java is mostly back-end systems and Android. JavaScript runs websites in your browser.
  • “Java is old, so it is dead.” Old, yes. Dead, no. It still runs banks, Android, and huge servers, and gets a new version every six months. Old here means proven.
  • “Java is too hard for beginners.” It asks for more structure than some languages, but that structure teaches good habits. Many people learn Java first and do fine.

🧩 What You’ve Learned

Nice start. The main points:

  • ✅ Java is a high-level, object-oriented programming language used to give computers instructions.
  • ✅ It was built around one big idea: Write Once, Run Anywhere.
  • ✅ It powers Android apps, banking systems, and the back ends of huge sites like Netflix and Amazon.
  • ✅ A Java program lives inside a class, and it starts running from the main method.
  • ✅ Your code is turned into bytecode, and the JVM runs that bytecode on any machine, which is why one program works everywhere.

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    What is Java, in simple terms?

    Why: Java is a high-level, object-oriented programming language used to write instructions a computer can follow.

  2. 2

    What does 'Write Once, Run Anywhere' mean?

    Why: You write Java once, and the JVM on each machine runs the same bytecode, so it works everywhere.

  3. 3

    Where does a Java program begin running?

    Why: Java looks for the main method and starts running the program from there.

  4. 4

    Who is known for creating Java, and when was it released?

    Why: Java was created by a team led by James Gosling at Sun Microsystems and released in 1995. It is now owned by Oracle.

🚀 What’s Next?

Now you know what Java is, where it came from, and how it runs. The next step is to get Java onto your own computer so you can run code yourself. Let’s set it up together.

Installing Java

Share & Connect