Java Program Structure
for developing java application.
package details
{
Data Members
User_defined Methods
public
static void main(String[] args)
{
Block of Staments
}
}
Implementing a Simple Java Program
Creating hello
java example
import java.io;
class Hello
{
public static void main(String[] args)
{
System.out.println("Hello Java");
System.out.println("My
First Java Program");
}
}
To compile: javac
Hello.java
To execute: java
Hello
Understanding
Hello java program
1.
class keyword is used
to declare a class in java.
2.
public keyword is an access modifier which
represents visibility, it means it is visible to all.
3.
static is a keyword, if we declare any method
as static, it is known as static method. The core advantage of static method is
that there is no need to create object to invoke the static method. The main
method is executed by the JVM, so it doesn't require to create object to invoke
the main method. So it saves memory.
4.
void is the return type of the method, it
means it doesn't return any value.
5.
main represents startup of the program.
6.
String[] args is used for command line argument.
7.
System.out.println() is used to
print statements.
Valid java main
method signature
- public static void main(String[] args)
- public static void main(String []args)
- public static void main(String args[])
- public static void main(String... args)
- static public void main(String[] args)
- public static final void main(String[] args)
- final public static void main(String[] args)
Invalid java
main method signature
- public void main(String[] args)
- static void main(String[] args)
- public void static main(String[] args)
- abstract public static void main(String[] args)
No comments:
Post a Comment