Java Tutorial
Java is a high-level programming language developed by Sun Microsystems and was released in May 1995.
Java can run on multiple platforms, such as Windows, Mac OS, and various UNIX versions.
This tutorial will help you understand the Java programming language better through simple examples.
The mobile operating system Android uses Java programming language for most of its code.
My First JAVA Program
Below is a simple example to demonstrate Java programming. Create a file HelloWorld.java (filename must match the class name), with the following code:
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 it is recommended to use String[] args
to avoid ambiguity and misreading.
Running the above example will produce the following output:
$ javac HelloWorld.java
$ java HelloWorld
Hello World
Command Explanation:
We used two commands, javac and java.
javac is followed by the java file name, such as HelloWorld.java. This command is used to compile the java source file into a class bytecode file, for example: javac HelloWorld.java.
After running the javac command, if the compilation is successful and there are no errors, a file named HelloWorld.class will be created.
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:
Start Learning JAVA Programming
-
-
-