Loading

Interview Questions of java-first-program

Scenario: 

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


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.


Scenario: 

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


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:

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


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.