Page 57 - iPro_trackGPT_V5_Class8
P. 57
The HelloWorld class includes a method named main(), which is declared with three Java
keywords: public, static, and void. The main() method should look like this:
public static void main(String args[])
In the main method:
public means the method is accessible from outside the class.
static means the method belongs to the class rather than to instances of the class.
void means the method does not return a value.
The parameter String[] args is an array of strings that can hold command-line arguments provided
when the program is executed from the command prompt. The name args is conventional but can
be replaced with any valid identifier.
In BlueJ, the main method can be defined without arguments, if necessary, though the standard
form includes String[] args.
The main method in this example contains a single statement:
System.out.println(“Hello from TrackGPT”);
This statement outputs the text "Hello from TrackGPT" to the console. The System.out refers to
the standard output stream, typically the console or terminal window. The println() is a method
that prints the specified string and then moves the cursor to the next line.
The semicolon at the end of the System.out.println() statement marks the end of the line. It is
also known as the line terminator. Since the Java compiler ignores extra spaces and indentations,
it’s important to use a semicolon to indicate the end of each statement in Java.
BASIC FUNDAMENTALS OF JAVA
Like other programming languages, Java also provides some fundamental concepts which are
given below:
Identifiers
Keywords
Data Types
Literals
Variables
Comments
Let us discuss these in detail.
Identifiers
A Java program assigns an identifier, such as a class or method, to uniquely identify it. A program
uses it to identify variables, methods, classes, and other entities.
Rules for Naming Identifiers
These are the guidelines you need to follow when creating names for classes, methods, and
variables in Java:
An identifier can include letters, digits (0–9), underscores (_), and dollar signs ($).
An identifier cannot start with a digit.
Keywords cannot be used as identifiers.
Program Coding 55

