Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Tutorial

Java Tutorial

Java is a high-level programming language introduced by Sun Microsystems in May 1995.

Java can run on multiple platforms, such as Windows, Mac OS, and various UNIX versions.

This tutorial uses simple examples to help you better understand the Java programming language.

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

Java Online Tools

JDK 11 Online Chinese Manual


My First JAVA Program

Below, we use a simple example to demonstrate Java programming. Create the file HelloWorld.java (the file name must match the class name), with the following code:

Example

public

class

HelloWorld

{

   

public

static

void

main

(

String

[

]

args

)

{

       

System

.

out

.

println

(

"Hello World"

)

;

   

}

}

Run Example »

Note:String args[] The difference between String[] args Both can be executed, but it is recommended to use String[] args, which avoids ambiguity and misinterpretation.

Running the above example produces the following output:


$ javac HelloWorld.java
$ java HelloWorld
Hello World

Explanation of the execution commands:

Above we used two commands javac and java.

javac is followed by the file name of the java file, for example HelloWorld.java. This command compiles the java source file into a class bytecode file, such as: javac HelloWorld.java.

After running the javac command, if compilation succeeds without errors, a HelloWorld.class file appears.

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

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

GIF demonstration: