It2EDU

Sunday, December 25, 2016


Java Program - Basic Syntax:




public class ClassName {


          public static void main(String args[]){


         Variables;

    
         Statements;


    }

}



First Java Program:










public class FirstJavaProgram
{





   /* This is my first java program. 


    * This will print 'Hello World' as the
output


    */


      public static void main(String []args) {





      
System.out.println("Welcome to java world"); // prints welcome
to java World





    }


}  





First type the above code in Note pad and save with name "FirstJavaProgram.java" .





Compilation of Java program:













C:\>mydisk>javac FirstJavaProgram.java





Run the above program.





C:\>mydisk>java FirstJavaProgram







Out put is:





Welcome to java world.





Have a look at the Public static void main().





 Publicmain() method is the first method called by java environment when a program is executed so it has to accessible to from the java environment. Hence the access specifier is Public.





static:  Java environment should be able to call this method without creating an instance of the class.so this method must be declared as static.





void: Void does not return any thing so main() method is void.











 
















Java Primitive data Types and its Ranges:


































































Data Type



Size/Width



Range



Group



Byte



8-bits



-128 to 127  (-28
to 28-1)



 Integer Group



Short



16-bits



-32768 to 32767  (-216
to 216-1)



Int



32-bits



–2,147,483,648
to 2,147,483,647


  (-232 to 232-1)



Long



64-bits



–9,223,372,036,854,775,808 to
9,223,372,036,854,775,807


(-264 to 264-1)



Float



32-bits



1.4e–045
to 3.4e+038



Floating point



Double



64-bits



4.9e–324
to 1.8e+308



Char



16-bits



216   \u0000 to \uFFFF



Character



Boolean



1-bit



20
True or false



Boolean