Skip to content

Java Introduction

What is Java?

Java is a powerful, versatile, object-oriented high-level programming language, first released by Sun Microsystems (now part of Oracle Corporation) in 1995. With its "Write Once, Run Anywhere" (WORA) philosophy, it quickly became one of the most popular programming languages in the world.

This means that the Java code you write can run on any Java-supported platform without modification, whether it's Windows, macOS, Linux, or mobile devices.

Quick Start with Your First Java Program

The following demonstrates Java programming through a simple example. Create a file named HelloWorld.java (the filename must match the class name) with the following code:

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

NOTE

String args[] and String[] args both work, but String[] args is recommended to avoid ambiguity and misreading.

Run the above example with the following commands to see the output:

bash
$ javac HelloWorld.java
$ java HelloWorld
Hello World, Java!

Command Explanation:

In the above example, we used two commands: javac and java.

javac is followed by the Java source filename, such as HelloWorld.java. This command compiles the Java source file into a class bytecode file, e.g.: javac HelloWorld.java.

After running the javac command, if compilation is successful without errors, a HelloWorld.class file will be created.

java is followed by the class name from the Java file, such as HelloWorld, e.g.: java HelloWorld.

Note: Do not add .class after the java command.

Content is for learning and research only.