Hackerthink logo

THE MOST POPULAR SITE FOR DEVELOPERS.

Java Tutorial

Java is an advanced programming language launched by Sun Microsystems in May 1995.

Java can run on multiple platforms, such as Windows, Mac OS and many other UNIX versions of the system.

This tutorial will give you a better understanding of the Java programming language through simple examples.

Most of the code of the mobile operating system Android is programmed in the Java programming language.

Java online tools

JDK 11 online manual

JDK 1.6 online manual (old version)

My first JAVA program

Below we use a simple example to demonstrate Java programming, create a file HelloWorld.java (file name must be consistent with the class name) , the code is as follows:

Example

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

Note: Both String args[] and String[] args can be executed, but String[] args is recommended to avoid ambiguity and misunderstanding.

Run the above example, the output results are as follows:

$ javac HelloWorld.java
$ java HelloWorld
Hello World

Execute command analysis:

Above we have used two commands javac and java .

What follows javac is the file name of the java file, such as HelloWorld.java. This command is used to compile java source files into class bytecode files, such as: javac HelloWorld.java .

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

Java is followed by the class name in the java file, for example, HelloWorld is the class name, such as: java HelloWorld.

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

Start learning JAVA programming