Posts

Showing posts with the label Java Main Method

Java Basics: Main Method and println() Method

Main Method in Java The main method is the entry point of a Java program. During program execution, the JVM (Java Virtual Machine) searches for the main method to start the execution. The JVM uses an inbuilt mechanism to locate the main method, which must be written in lowercase exactly as main. Java is case-sensitive, so any change in the method name will cause a runtime error. If the main method is present, the JVM: Locates the bytecode of the main method Converts the bytecode into machine-specific code Passes the machine code to the operating system Produces the output of the Java program If the main method is not found, the JVM generates a runtime error. Syntax of Main Method: public static void main(String[] args) {     // program execution starts here } println Method in Java The println() method is used to display data on the console output. Key points: It prints the given data on the console After printing, it moves the cursor to the next line The println() method bel...