Structure of java program To learn any language, the best way is - TopicsExpress



          

Structure of java program To learn any language, the best way is to execute some basic programs. Here I am writing basic hello word program. Program 1 : Hello.java class Hello { public static void main(String args[]) { System.out.println(“Hello java user”); } } From 1st program you can understand how to write the code. Here I am explaining program line by line. Class declaration The 1st line : class Hello ----------- Declare the class named Hello. Class is a predefined keyword available in java. Opening brace ---------------- Every class available in java starts with “{” and ends with “}” because java is object oriented language and each and everything written in it in inside the class. Main method declaration ---------------------------- The line is public static void main(String args[]) here we are defining the method main(). Every java program must include main() method. *Public : we are using public keyword for deciding the access i.e public is the access specifier that decides the scope. *Static :static keyword specifies that we are able to create only single copy of the method throughout the program. So only one main() method will be available in a whole Java program. *void: This keyword states that main method does not return any value. *main() : main() is the predefine method available in java and execution of program always starts from main() method. *String args[] : It is the parameter to the main method which contain array of the objects of type String with array name args. Output line -------------- Line is System.out.println(“Hello java user”); println() method is the member of out object which is the static data member of a System class. println() method always puts the cursor to the next line.
Posted on: Sat, 24 Aug 2013 05:16:46 +0000

Trending Topics



Recently Viewed Topics




© 2015