Introduction to Java with a Step-by-Step First Program Tutorial

Welcome back to the WorldTera Programming Languages series! In our previous guides, we took our first steps into the coding world. We used Python to write a program in under five minutes, and we explored C# to understand how strongly-typed languages protect our code from silly mistakes.

If you have been following along, you are already starting to think like a programmer. But there is one massive, legendary language we haven’t touched yet—a language that runs on over 3 billion devices worldwide, from the Android phone in your pocket to the massive cloud servers powering Amazon and Spotify.

That language is Java.

Today, we are going to break down exactly what makes Java so special, how it works, and write your very first Java program from scratch!

Java Featured

Java's Superpower: "Write Once, Run Anywhere"

When programming languages were first invented in the early days of computing, they had a frustrating limitation. If you wrote a program on a Windows computer, that code was permanently tied to Windows. If you wanted it to run on a Mac or a Linux machine, you had to rewrite large portions of your code from scratch.

In 1995, the creators of Java solved this problem forever with a simple philosophy: Write Once, Run Anywhere (WORA).

Instead of talking directly to your computer’s specific operating system, Java talks to a special, universal translator software installed on the machine. This means you can write your Java code on a laptop, and that exact same code will run flawlessly on a smart refrigerator, a massive corporate server, or a smartphone without changing a single line of logic.

The Three Pillars of Java

To make this universal translation happen, Java relies on three core tools that work together behind the scenes. Beginners often get confused by these acronyms, but they are actually very simple when you break them down:

LayerWhere It SitsWhat It Does
JDK (Java Development Kit)Developer's ComputerThe complete toolkit for writing and compiling Java code
JRE (Java Runtime Environment)The Target DeviceContains the libraries needed to run Java applications
JVM (Java Virtual Machine)Core Execution EngineConverts compiled Java code (bytecode) into instructions the computer can understand and execute

Write Your First Java Program

Let’s put theory into practice. You don’t need to install any heavy software on your computer to try Java today. We can use a free, instant online playground.

  1. Head over to your web browser and open Programiz or OneCompiler.
  2. Clear out any text currently inside the editor, and type out this exact code:

 

				
					public class Main {
    public static void main(String[] args) {
        System.out.println("Hello WorldTera!");
    }
}
				
			
Now, click the Run button at the top of the page. Look down at the console window at the bottom of your screen. You will see the words Hello WorldTera! print out perfectly!

Breaking Down the Code

If you compare this to Python, Java looks like it requires a lot of extra words just to print a single line of text. Let’s demystify what those words actually mean so they don’t look scary:

  • public class Main: In Java, all code must live inside a Class (which is just a blueprint or a container for your code). We called our container Main.
  • public static void main(String[] args): This is the “front door” of your program. Whenever you run a Java application, the computer automatically searches for this exact line of text to figure out where the instructions begin.
  • System.out.println(…): This is Java’s built-in command for “Print a line of text to the screen”.

Storing Data

Now that we can print text, how do we store information? Just like we learned with C#, Java is a “strongly-typed” language.

Think of variables in Java like perfectly labeled Tupperware containers. If you build a container meant for whole numbers, you absolutely cannot put text inside it. You must declare exactly what shape the data takes before you use it.

Let’s add some data to our playground. Change the code inside your main method to look like this:
				
					public class Main {
    public static void main(String[] args) {

        String websiteName = "WorldTera";
        int releaseYear = 2025;
        boolean isAwesome = true;

        System.out.println("Website: " + websiteName);
        System.out.println("Release Year: " + releaseYear);
        System.out.println("Is it awesome? " + isAwesome);
    }
}
				
			

By forcing you to label your data as a String (text), int (whole numbers), or boolean (true/false), Java prevents hundreds of unpredictable bugs from ruining your program later on.

Thinking in Objects: The Cookie Cutter Analogy

As you continue learning Java, you will hear the phrase Object-Oriented Programming (OOP) constantly.

Stop thinking of a computer program as a top-to-bottom list of chores. In Java, you build programs by creating “Objects”. The best way to understand this is the cookie-cutter analogy:

  • A Class is the metal cookie cutter. It defines the shape, size, and features.
  • An Object is the actual cookie you bake. You can use the same cutter to make a chocolate chip cookie, a sugar cookie, or a gingerbread cookie.

In a real application, you might write a single User Class. Then, when a thousand different people sign up for your website, Java uses that class to stamp out a thousand unique User Objects, each holding its own name and password safely!

Common Beginner Traps

Because Java is so strict, beginners often run into errors during their first week. Watch out for these three common traps:

  • The Missing Semicolon: In Java, every single command must end with a semicolon (;). Think of it like the period at the end of an English sentence. If you forget it, Java refuses to read the code.
  • Case Sensitivity: Java treats uppercase and lowercase letters as completely different things. ‘system.out.println’ (with a lowercase ‘s’) will cause a massive error. Always double-check your capitalization!
  • Mismatched Brackets: Notice those curly braces { } in your code? They act like walls separating different rooms in your program. Every time you open a bracket {, you must eventually close it }.

Why Learn Java Today?

While Java requires a little bit more typing than Python, learning it gives you an incredible career advantage. It forces you to understand clean coding structures, object-oriented concepts, and memory safety right from day one. Once you master the strict fundamentals of Java, learning almost any other programming language becomes a walk in the park.

Java also teaches you how to think like a developer rather than just writing code that works. It encourages you to break problems into smaller, structured parts and design solutions that are scalable and reusable. This mindset is valuable not just in Java, but in any programming language or software development role you pursue.

Another major benefit of Java is its strong community and long-term stability. With decades of development and continuous updates, Java has a huge ecosystem of tools, frameworks, and libraries that make it easier to build real-world applications and grow as a developer over time.

Java Code

What’s Next?

Spend a few minutes getting familiar with your workspace and running some code. Try creating new int variables, do some basic math (like int total = 5 + 10;), and print the result using your System.out.println(); command.

Now that you know how the foundational Java language works, you are ready to see how real-world developers use it to build fast, modern web applications without writing everything from scratch. Later in our Frameworks & Libraries series, we will dive into the world of Java frameworks and meet the ultimate backend time-saver: Spring Boot.

Stay tuned to WorldTera, and happy coding!

Disclosure: This post may contain affiliate links. If you buy through them, we may earn a commission at no extra cost to you.

Comments

Thanks for visiting! We encourage lively, respectful discussions. Share your thoughts, questions, or opinions, but please be kind and avoid harmful language. Let’s keep the conversation friendly and productive for everyone!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments