Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Sunday, June 9, 2013

Define different main method format in Java

Do you know what do you mean of “public static void main()”?

Public

It  is “access specifier” ; so it is basically define the scope of methods, classes and interface and etc.  you know JRE (Java Run-time Environment) is the outside part of class. if we use other access specifier (private, protected) so you can’t access the that class. If you are not used any access specifier. So compiler use the default access specifier.
Static

In class there are two type members
      1-Instance member
          represent attributes and behavior of individual object. By default all the      member of class is instance member.
     2-class member
          represent attributes and behavior of whole class. Denoted  by  “static”   keyword.
So static keyword are used define the class member.
Void

Functions are always requires a return type so void is one of them to returns value implicitly. If any error occur in the program so O.S returns the value with the help of  JRE.
Main:

only method name
Are you know the given below syntax are valid or not valid  in JAVA?

Syntex-(Modifier ReturnType MethodName() )

Static public void main (String [] arg ) true
Static public void main(String[][] arg) runtime error NoSuchMethodError
Static void public main (String [][] arg) compile time error
Void static public main (String arg[]) compile time error
 public static void main (String arg) runtime error NoSuchMethodError
Public void static main ([] String arg) compile time error
Public static void main (String[] arg[]) runtime error NoSuchMethodError
Public static void main() runtime error NoSuchMethodError

                                                 Author-Ravi Kumar


Sunday, June 2, 2013

Basic Interview Question in Java



Introduction

Java, now it’s time to play with JAVA. I started with a new existing point.

Can we use multiple main in a program

Yes; we can use multiple “main()” method in a java program. But the both main methods argument should not be same, as you know, the  java programs execution is start from “main()” method means (
public static void main(String arg[]), then simply declare the second ‘main()” method in this main method for execution, Now the given below example shown you how to do it.

E
xample

 class A
{
public static void main(String arg[])
{System.out.println("welcome");
main();

}
public static void main()
{
System.out.println("first");
}
}

Output

Can we run the program without main(String [] args) method

Yes we can run a java program without  main() method. Because java provide a functionality with the use of “static” keyword and that “static” keyword can be a block or static data member or static method,  firstly execute whenever you compile a  java program. Let’s see, it works or not.

Example
 class A
{
static
{
System.out.println("welcome");
System.exit(0);
}
}Output



Can we change the main thread name?

Yes, we can change the main thread name.

Can we print the message before the main method execution?

Yes, we can print the message before the main method. Let’s see how

Example
class A
{
static
{
System.out.println("welcome");
}
public static void main(String arg[])
{System.out.println("main method");}}Output

Kashmir 370 and 35A : The Wound of india

क्या है जम्मू-कश्मीर में लागू धारा 370,35A पूर्ण विवरण Know about 370 act in Jammu एक बार फिर से राजनीति गलियारे में धारा 370,35A को ल...