Loading

Scenario 1: Program Entry Point

Imagine you are about to launch a new Java application. You write your code, but where does the program actually start running?


Interview Question

What is the meaning of 'public static void main(String[ ] args)' in Java ?


Answer: 

  • public -  Access Modifier
  • static  -  Reserved Keyword 
  • void   -   No value is returned after execution
  • main  -   The program start running for compiling 
  • String[] args -  Allows command-line input when executing the program.

Tips: Always remember that public static void main(String[] args) is the entry point of any Java application.



Scenario 2: First-Time Execution

You are just finished writing your first Java file, HelloWorld.Java, and want to see it in action.


Interview Question

What are the steps to compile and run a Java program ?


Answer:

Step - 01:  Write the Java program in a .Java file (Ex- Helloworld.java).


Step - 02:  Compile the program using command prompt by giving instruction.

-->  javac Helloworld.java


Step - 03:  Run the program using.

-->  java Helloworld

Output will display.


Scenario 3: Output on Screen

You want your program to greet the user or display a result.


Interview Question

What is the purpose of 'System.out.println()' in Java?


Answer:

  • System.out.println() is used to print messages to the console.
  • It is a built-in Java method from the System class.

Example: 

  • System.out.println("Hello world!")
  • Hello world! in the output will printed.