Now we will learn how to write the first java program. We can write a simple Hello World java program easily but first need to understand of required Software for java program
For executing any java program we need given things.
/* This is a simple Java program.
Call this file "FirstProgram.java". */
class FirstProgram {
//Your program begins with a call to main
public static void main(String args[]){
System.out.println("Hello World");
}
}
save this file as FirstProgram.java
To compile: javac FirstProgram.java
To execute: java FirstProgram
Result: Hello World
You will see it in almost every Java program. You know, the declaration public static void main. It is the means by which you create a main method within the Java application. JVM will always look for a specific method signature to start running an application, and that would be public static void main(String args[]).
System is a predefined class that provides access to the system, and out is the variable of type output stream that is connected to the console. Output is actually accomplished by the built-in println( ) method.
The comments are the statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. They can either be multi-line or single line comments. A multi-line comment must begin with /* and end with */. For single line you may directly use //.