Java Introduction
Java is a general-purpose, object-oriented programming language used to build everything from mobile apps to large enterprise systems. This course will teach you Java from the ground up, starting with the basics.
What is Java?
Java was created by Sun Microsystems (now owned by Oracle) and released in 1995. It was designed around one core idea: “write once, run anywhere.” Java code is compiled into an intermediate form called bytecode, which runs on the Java Virtual Machine (JVM). Because every major operating system has its own JVM, the same compiled Java program can run on Windows, macOS, and Linux without changes.
Why learn Java?
- It is one of the most widely used languages for Android app development.
- Large companies rely on it for backend systems, so Java developers are in high demand.
- Its strict, statically-typed structure helps you catch mistakes before your program even runs.
Your First Java Program
Every Java program starts with a class. Inside that class, the main method is the entry point — it’s the first code that runs when your program starts. Here is a simple example that prints a message to the screen:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Output:
Hello, World!
How it works
public class Maindefines a class namedMain. In Java, code must live inside a class.public static void main(String[] args)is the method Java looks for and runs first. Every standalone Java program needs one.System.out.println(...)prints text to the console, followed by a new line.- Every statement in Java ends with a semicolon
;, and blocks of code are wrapped in curly braces{ }.
Compiling and Running Java Code
Java source files end in .java. Before a program can run, it must be compiled into bytecode using the javac compiler (for example, javac Main.java), then executed with the java command (java Main). The compiler produces a file named Main.class containing the bytecode; running it starts the JVM, which executes that bytecode and produces the output shown above.
Now that you’ve seen the basic shape of a Java program, the next lesson will walk through setting up Java on your own computer so you can start writing and running code yourself.
