My first Java program
Here we show Java programming through a simple example, creating a file Helloworld.java (the filename needs to match the class name) with the following code:
Instance
public class HelloWorld {
public static void Main (string[] args) {
System.out.println ("Hello World");
}
}
Note: String args[] and string[] args can be executed, but it is recommended to use the string[] args, which avoids ambiguity and misreading.
Running the above example, the output is as follows:
$ Javac Helloworld.java
$ Java HelloWorld
Hello World
To perform a command resolution:
Above we used two commands Javac and Java.
Javac is followed by the file name of the Java file, such as Helloworld.java. This command is used to compile the Java source file into a class bytecode file, such as: Javac Helloworld.java.
After running the Javac command, a helloworld.class file appears if there is no error in compiling successfully.
Java followed by the class name in the Java file, such as HelloWorld is the class name, such as: Java HelloWorld.
Note: Do not Add. class after the Java command.
Examples of my Java programs show