As we have successfully displayed the result “Hello World” on the screen, we will now understand each line of code as follows:
- Public Class Personalinfo: This line creates a new class named Personalinfo, and the public class must be defined in a file that has the same name, Personalinfo.java. This definition helps the Java compiler determine the name of the public class to be created before reading the file contents.
- Public Static Void Main: This line represents the main method that the JVM (Java Virtual Machine) calls when the program is loaded into memory. This method is used to execute the program. Once this method finishes execution, the program terminates within the Main Function.
- Keywords used:
o public: Defines the accessibility scope of the main method. By using public, this method can be called by external programs such as the JVM.
o static: Defines the scope of the main method. By using static, this method can be called by external programs like the JVM without creating an object of the class first.
o void: Defines the return type of the main method. By using void, this method does not return any value.
o main: The name of the method.
o String []args: Represents the arguments passed through the command line when executing the Java command. - System.out.println() Method: System.out represents the primary console, and the println() method takes "Hello World" as input and displays it on the console output.
Popular Java Editors
To write Java programs, you need a text editor. There are several modern and popular IDEs described briefly below:
- Notepad: On Windows machines, you can use text editors such as Notepad (recommended for this lesson) or WordPad. Notepad++ is also a free text editor that provides enhanced features.
- NetBeans: It is an open-source and free Java IDE that can be downloaded from www.netbeans.org/index.html.
- Eclipse: It is also a Java IDE developed by the Eclipse open-source community and can be downloaded from www.eclipse.org
- JCreator: This is an IDE for Java designed specifically for Windows. It is lightweight, fast, and particularly suitable for Java developers who need an efficient tool to write, debug, and manage Java projects.
Basic Syntax
When working with Java programs, it is very important to remember the following points:
- Case Sensitivity: Java is case-sensitive, which means identifiers like
Helloandhellowill have different meanings in Java. - Class Names: For all class names, the first letter should be capitalized. If multiple words are used to form a class name, the first letter of each inner word should also be capitalized.
Example:class Personalinfo Method Names: All method names should begin with a lowercase letter. If multiple words are used to form the method name, the first letter of each inner word should be capitalized.
Example:public void myMethodName()Program File Name: The program file name should match the class name. When saving the file, use the class name (remember that Java is case-sensitive) and add.javaat the end of the name.
If the file name and class name do not match, your program will not compile.
However, note that if there is no public class in the file, the file name may differ from the class name, and a public class is not necessarily required in a file.
Example: IfPersonalinfois the class name, then the file should be saved asPersonalinfo.java.public static void main(String args[]): The execution of a Java program begins from themain()method, which is a mandatory part of every Java application.
Source Code:
class MyClass {
public static void main(String[] args) {
System.out.println("This is MyClass.");
}
}
Result:
Watch the video:

