Loading

Q1. What is the meaning of 'public static void  main(String[ ] args)' in Java ?
'public static void main(String[ ] args)' is the entry point of a Java application.
The Java Virtual Machine (JVM) starts program execution from this method.

Each part of this statement has a specific purpose:

  • public Makes the method accessible from anywhere. The JVM must be able to call this method from outside the class.
  • static Allows the JVM to call the method without creating an object of the class.
  • void Specifies that the method does not return any value after execution.
  • main This is the predefined method name recognized by the JVM as the starting point of execution.
  • String[ ] args Used to accept command-line arguments passed while running the program 
Without this method, a Java application cannot start execution. 



Q2. What are the steps to compile and run a Java program ?
To compile and run a Java program, the following steps are required:

1. Write the Java source code Save the program with a .java extension.
Example: Helloworld.Java

2. Compile the program
Use the Java compiler to convert source code into bytecode:

javac HelloWorld.java
This generates a .class file.

3. Run the program
Execute the compiled bytecode using the JVM

java HelloWorld

if there are no compilation errors, the program output will be displayed on the console.



Q3. What is the purpose of 'System.out.println( )' in Java ?
Sytem.out.prinln( ) is used to display output on the console.

  • System is a predefined class in Java.
  • out is a static output stream connected to the console.
  • println( ) prints the given message and moves the cursor to a new line.
It is commonly used for:

  • Displaying messages
  • Printing results 
  • Debugging programs
Example

System.out.println("Hello World!");


Output

Hello World!

This method is one of the most frequently used output statements in Java programs.