Posts

Showing posts with the label Java Keywords

Variables in Java - සිංහල

අද අපි Java වල ඇති විචල්‍ය(variables)  ගැන කතා කරමු. Javaහි ප්‍රධාන වශයෙන්ම අපට variables වර්ග 4ක් ලෙස සලකා බලන්න පුළුවන්. 1. Instance Variables (Non-Static Fields) Instance variables යොදාගන්නේ classes වල objects (instances) වලට reference කරන්නයි. 2. Class Variables (Static Fields) මෙහිදී අපි static යන  modifier එක variable එකේ නම ඉදිරියෙන් යොදනවා.එමගින් compiler එක දැනගන්නවා හරියටම මේ නමින් එක variable එකක් විතරයි තියෙන්නේ යන්න. අපි final   කියන keyword එකත් යෙදුවොත් variable එකේ අගය වෙනස් වෙන්නේ නැති බව එකෙන් කියවෙන්නේ. 3. Local Variables මේ variables declare කරන්නේ method එකක් තුල ය. අදාළ method එකෙන් පිට class එකේ වෙන තැනක variable එක භාවිත කරන්න බැහැ.      4. Parameters අපි main method එක උදාහරණයක් විදිහට සලකමු.  public static void main(String [] args){} මෙහි  args  variable එක method එකට parameter එකක් වේ. ඒවගේම  constructors ද    parameter variables arguments ලෙස ගනී.    ඔයාට variables සහ fi...

Variables in Java

Today let's talk about variables in Java. In Java mainly we can have four different variable types. 1. Instance Variables (Non-Static Fields)     Instance variables are used to refer the objects(instances) of classes. 2. Class Variables (Static Fields)     Here we use static modifier in front of the variable name and this tells the compiler that there is           exactly one copy of this variable in existence.   If we use the keyword final also then that would           indicate that the value of the variable will never change. 3. Local Variables     These variables are declared inside a method and they are only visible within that particular                  method and not accessible from the rest of the class.   4. Parameters     Let's take the main method as an example, public static void main(String [] args){ } ,here args...