Java Learning Made Easy by Dheeraj Mehrotra - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Example Program in JAVA

01034.jpg01035.jpg01036.jpg01037.jpg01038.jpg

class exampleprogram

01039.jpg

{

01040.jpg

public static void main(string args[ ])

01041.jpg

{

01042.jpg

System.out.println(“Hail The World !”);

01043.jpg

}

01044.jpg01045.jpg

}

01046.jpg01047.jpg01048.jpg01049.jpg01050.jpg01051.jpg01052.jpg01053.jpg01054.jpg01055.jpg01056.jpg01057.jpg01058.jpg01059.jpg01060.jpg01061.jpg01062.jpg01063.jpg01064.jpg01065.jpgattention@computerscienceexpertise.com

 

01066.jpg01067.jpg01068.jpg01069.jpg01070.jpg01071.jpg01072.jpg01073.jpg01074.jpg01075.jpg01076.jpg01077.jpg01078.jpg01079.jpg01080.jpg01081.jpg

In the above program, the first line
class exampleprogram

01082.jpg

{public static void main(string args[ ])class exampleprogram {System.out.println(“Hail The World

01083.jpg01084.jpg!”);}}

 

declares a class named exampleprogram, where class is the reserve word.
Exampleprogram is an identifier as supplied by the programmer.

 

01085.jpg01086.jpg01087.jpg01088.jpgThis is followed by brace {, which indicates the beginning of the block of executable statements.

 

01089.jpg01090.jpgThe third line :

 

01091.jpg01092.jpgpublic static void main(string args[ ])

 

01093.jpg01094.jpg01095.jpg01096.jpgdefines the function main( ). The declaration of the main() function contains the following keywords:

 

01097.jpg01098.jpg01099.jpgPublic, Static and Void.

 

01100.jpg01101.jpg01102.jpg01103.jpgThe Public keyword acts as an access specifier which declares the main function to be publically accessible for other classes.

 

01104.jpg01105.jpg01106.jpg

The Static definition declares that the very function or method is independent of the entire class

01107.jpg

and does not figure as a part of any objects of the class. In the above program, the class

01108.jpg01109.jpg

exampleprogram is unchanging or static, as a state. The term static means unchanging and implicitly final.

01110.jpg01111.jpg01112.jpgThe Void is a data type modifier which defines the main() function of no return type.
01113.jpg01114.jpgThe argument of the main() function lies within braces eg. (String args[ ]), here String args[ ] 01115.jpgdeclares an argument parameter as args containing an array of objects of the class type String.
01116.jpgattention@computerscienceexpertise.com
It specifies that the main method takes an argument that is an object of string.

01117.jpg01118.jpg
01119.jpg01120.jpg01121.jpg01122.jpg01123.jpg01124.jpg01125.jpg01126.jpg01127.jpg01128.jpg01129.jpg01130.jpg01131.jpg01132.jpg01133.jpg01134.jpg01135.jpg01136.jpg01137.jpg01138.jpg