Friday, October 19, 2018

Java Programming sinhala tutorial - Outline - Part 2

Content of a Java source code file (Outline)

Java source code එකක ප්‍රධාන වශයෙන් class name , main method , method body යන කොටස් තිබිය යුතුය. 


 Java source code එකක් ලිවීමේදී ප්‍රධාන වශයෙන් අපි පහත සදහන් කරුණු ගැන සැලකිලිමත් විය යුතුයි.

       1. Method body එකෙහි command එකකට වඩා වැඩි නම් command අතර semicolon (;) ලකුණ අනිවාර්යෙන් යෙදිය යුතුයි.
       2. අපිට main method එක declare කළ හැකි ක්‍රම කිහිපයක් පවතී.
පහත පරිදි main method එක ලියු විට source code එක compile හා run කල හැක.

Legal, Valid
  • public static void main(String args[]){}
  • static public void main(String args[]){}
  • static public void main(String studentname[]){}
  • static public void main(String[] args){}
  • static public void main(String... args){}
පහත පරිදි main method එක ලියු විට source code එක compile කල හැකි වුවත් run කල නොහැක.
Legal, Run time error
  • public static void Main(String args[]){}
  • public void main(String args[]){}
  • static void main(String args[]){}
  • void main(String args[]){}
  • public static void main(String args){}
  • public static void main(){}
පහත පරිදි main method එක ලියු විට source code එක compile හා run කල නොහැක.
Illegal
  • public static main(String args[]){}
     3. source code එකේ class file එකකට වඩා ඇති විට, compile කළ විට class file වලට අදාළ byte code වෙන වෙනම නිර්මාණය වේ. ඒවා වෙන වෙනම run කල හැක. නමුත් අපි source code file එක එක්  වරක් පමණයි compile කරන්නේ.  


මම මේ file එක Demo.java ලෙස save කරගන්නවා. Demo.java file එක compile කල විට class file 2 ක් නිර්මාණය වී ඇති අයුරු පහත දැක්වේ. ඒවා වෙන වෙනම run කළ හැක.




     4. source code එකෙහි main method එකක් නැති විට, compile කල විට byte code එකක් නිර්මාණය වුවත් run කල නොහැක.



     5. Program එකක් run කල විට source code එකේ ඉහළ සිට පහලට run වේ.



     6. Source code එකෙහි statement එකක් හෝ කිහිපයක් comment කිරීමට // හෝ /*.....*/ සංකේත භාවිතා කල හැක.



අපි ඊලග ලිපියෙන් Java ගැන තවත් විස්තර ඉගෙන ගනිමු.

- චමෝදි -

0 comments:

Post a Comment