0
Sponsored Links


Ad by Google
Very interesting java interview question specially for freshers, here is 20 core java interview question for freshers. Sometimes interviewer asked you a very basic interview question to check your concept regarding java API. And start with question like what is static in java?, why main is public static etc. and sometimes to explain the different parts of main method.
So in this post, I am going to explain the very simple steps and you just need to at least remember these points.
Nowadays, only theory is not enough to crack an interview you have to also solve some logical question like How to balanced the parentheses?  with o(n) time and space complexity, program to remove duplicate characters from a String, Java program to find missing number etc. These types of question must needs solve.

Explain different parts of the main() method in java

I would suggest, before answering this question you should write a simple signature of the main method, and than pick one by one statement with very simple language.
OK, let me write a complete signature of the main method, public static void main(String...args)
And below are the 5 points.
  1. public is an access specifier, which says that this method is visible to everywhere.
  2. static because, you do not need an instance of the class to call the main method.
  3. void means, the main method will not return anything.
  4. main is a name of the method, In core java main is an entry point of your program.
  5. String...args means, the main method accept an argument as an array of String.
Enough for this question, although most of time when you finished with these steps, smart interviewer start with another question from your above explanation by asking why main method is static? he/she now want to go into the deep of the static keyword used here. So respect this question and explain more into the deep.

Now, lets see an simple example of main method, to print hello world in your console.
HelloWorld.java
package com.javamakeuse.poc;

public class HelloWorld {
 public static void main(String[] args) {
  System.out.println("Hello World");
 }
}

OUTPUT:Hello World

Sponsored Links

0 comments:

Post a Comment