Thursday, 1 July 2021

Basic program of Java || introduction of 'JAVA' (Part-2)

 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

  1. The package statement defines a namespace in which classes are stored.
  2. For ex: package india..

Import statement

  1. Java provides us many library classes which are defined in different packages.
  2. If we want to use these classes then we have to import them.
  3.  For eg: – import java.awt.Button;
  4.  import java.awt.TextField; 
  5.  import java.awt;
Global Declaration
  1. In this global declaration we can define only user defined data types such as classes, interfaces.
  2. 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:
  1. System.out.print( “INDIA” ) ; 
  2.  System.out.print( 2121 ) ; 
  3.  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



3 comments:

What is ladder if || Java Ladder if statement.

 Ladder if statement If a if statement is used within an else statement then such a control structure is called as ladder if statement. Synt...