Java is a programming language and computing platform first released by Sun Microsystems in 1995. It has evolved from humble beginnings to power a large share of today’s digital world, by providing the reliable platform upon which many services and applications are built. New, innovative products and digital services designed for the future continue to rely on Java, as well.
public class FirstJavaProgram {
public static void main(String[] args) {
System.out.println(“First Java Application”);
}
}
The FirstJavaProgram is a class name. A class is the basic unit of a Java program. All Java codes are grouped into a class. The definition of the class starts with an access modifier (such as public), which specifies the accessibility of classes, followed by the keyword class. Every class definition is enclosed within pair of curly brackets or braces ( { and } ). These braces mark the beginning and the end of the class.
The main method is a special method and is the entry point of the program execution. A Java class can only have one (1) main method.
In the example Java program, it contains only one (1) programming statement or command:
System.out.println(“First Java Application”);
System is a class.
out is an object defined in the System class.
Dots seperate classes, objects, and methods.
"First Java Application" is a literal string that is the argument to the println() method.
println() is a method. Method names are always followed by parentheses.
Every Java statements ends with a semicolon.
An identifier is a name of a program component, such as class, object, or variable.
These are the requirements in naming identifiers:
It must begin with a letter of the English alphabet, an underscore, or a dollar sign. An identifier cannot begin with a digit.
Identifiers name can only have any combination of letters, digits, underscores, or dollar sign. White spaces are not allowed. • It cannot be a reserved keyword.
Identifiers are case sensitive. For example, the identifier NUMBER is not the same asthe identifier number or Number.
It cannot be one of the following values: true, false, or null. These are not keywords, they are primitive values, but they are reserved and cannot be used.
When naming class identifiers, it is a good practice to begin the name with a capital letter.
Reserved words or keywords have special predefined meaning and cannot be used in naming variables, classes, methods, or identifiers. The Java language designates certain keywords that the compiler recognizes as reserved words. The following table lists all the reserved words in Java.
The main method is a special method in every Java application. When executing a Java program, execution always begins with the method main. All Java applications must include a class containing one (1) main method.
Defining the main method in any class:
public static void main(String[] args) { }
The basic parts of the main method are the heading and the body:
The public static void main(String[] args) is the heading.
The statements enclosed between the braces form the body of the main method. It contains the declaration and execution of the program.
Here are descriptions of the meaning and purpose of the terms used in the method heading:
The public keyword is an access modifier. The method heading should be public for the Java interpreter to call it and to run the class.
The static keyword means that a method is accessible and usable.
The void keyword indicates that the main method does not return any value when it is called.
The name of the method is the main. When executing a Java application, the JVM always executes the main method first.
The contents between the parentheses of the main method, which is String[] args, represent the type of argument that can be passed to the main method.