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.
OK, let me write a complete signature of the main method, public static void main(String...args)
And below are the 5 points.
Now, lets see an simple example of main method, to print hello world in your console.
HelloWorld.java
OUTPUT:Hello World
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.
- public is an access specifier, which says that this method is visible to everywhere.
- static because, you do not need an instance of the class to call the main method.
- void means, the main method will not return anything.
- main is a name of the method, In core java main is an entry point of your program.
- String...args means, the main method accept an argument as an array of String.
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