0% found this document useful (0 votes)
9 views3 pages

Class 10

Uploaded by

M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Class 10

Uploaded by

M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Main method

============
Our program contains main method or not.

Either it is properly declared or not.

It is not a responsibility of a compiler to check. It is a liability of a JVM to


look for main method always at runtime.

If JVM won't find main method then it will throw one runtime error called main
method not found.

JVM always look for main method with following signature.

signature:
--------
public static void main(String[] args)

If we perform any changes in above signature then JVM Will throw one runtime error
called main method not found.

Q) Explain main method in java?

public
------
JVM wants to call main method from anywhere.

static
------
JVM wants to call main method without using object reference.

void
-----
Main method does not return anything to JVM.

main
----
It is a identifier given to a main method.

String[] args
-----------
It is a command line argument.

We can perform following changes in main method.

1) Order of modifiers is not important. Incase of public static we can declare


static public also.
ex:
static public void main(String[] args)

2) We can change String[] in following acceptable formats.


ex:
public static void main(String[] args)
public static void main(String []args)
public static void main(String args[])

3) We can change String[] with var-arg parameter.


ex:
public static void main(String... args)

4) We can replace args with any java valid identifier.

5) Main method will accept following modifiers.


ex:
synchronized
strictfp
final

Command line arguments


======================
Arguments which are passing through command prompt such type of arguments are
called command line
arguments.

In command line arguments we need to pass input values at runtime command.

ex:
javac Test.java

java Test 101 raja M 1000.0


| | | |____ args[3]
| | |________ args[2]
| |_____________ args[1]
|_________________ args[0]

ex:
---
class Test
{
public static void main(String[] args)
{
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
System.out.println(args[3]);
}
}

System.out.println()
=====================
It is a output statement in java.

Whenever we want to display any data or user defined statements then we need to use
output stmt.

syntax:
-----
static variable
|
System.out.println();
| |
predefined predefined method
final class

Diagram: class10.1

You might also like