•Format of Java Program
• Output Statements
• First Program
General Format of Java Program
Package statement
Import statement
Global declaration
class Class Name
{
public static void main( String[] args )
{
Statements…..
…………………….
}
}
Package statement
- The package statement defines a namespace in which classes are stored.
- For ex: package india..
Import statement
- Java provides us many library classes which are defined in different packages.
- If we want to use these classes then we have to import them.
- For eg: – import java.awt.Button;
- import java.awt.TextField;
- import java.awt;
Global Declaration
- In this global declaration we can define only user defined data types such as classes, interfaces.
- In this section we can not define variables or functions.
public static void main( String[] args )/Function Main
- Execution of java program begins with function main.
- Function main must be in a class.
public:- It indicates that main function is
assessable.
static:- it indicates that function main
can be called without creating object.
void:- it indicates that function main
doesn't return any value.
String[] args:- it is used to receive
command line arguments.
Output Statements
System.out.print(value)
-Will print value on standard output device
-ex:
- System.out.print( “INDIA” ) ;
- System.out.print( 2121 ) ;
- System.out.print( 3.14 );
System.out.println(value)
-Will print value and a new line char on standard output device
- ex:
• System.out.println( “JAVA PROGRAM” )
System.out.printf(“foramtString”,args…)
-Will print formatted String on standard output device
-ex:-
float p = 3.14f;
System.out.printf( “Value of PI is %f” , p ) ;
First Program
PROGRAM
class Easy
{
public static void main(String[] args)
{
System.out.println(“HELLO WORLD”);
}
}
Output:-
:- HELLO WORLD
Thanks
ReplyDeleteNice👍👏
ReplyDeleteThanks
Delete