Variables සහ Data types

Variable එකක් කියන්නේ මොකක්ද? variable එකක් කියන්නේ අපේ computer වල memory එකේ values store කරන්න පුළුවන් location එකක්. අපි මොකක් හරි variable එකක් create කරාම එකේ value එක අපේ memory එකේ store වෙනවා. හිතමු අපි age කියලා variable එකක් create කරලා එකට 10ක් assign කලොත් 10 කියන අගය memory location එකක store වෙනවා. මේ value එක අරන් පසුව අපිට අවශ්‍ය විදියට බාවිතා කරන්න පුළුවන්.

Java කියන්නේ ගොඩක් type oriented language එකක්. ඒ කියන්නේ අපි declare කරන variables වල data type එක අපි අනිවාර්යයෙන් සදහන් කරන්න ඕනේ. Java වල variable එකක් create කරන standard model එක තමයි,

[data type] [variable name]=[value];

උදාහරණයක් විදියට ,

int counter=0;

මිට අමතරව මේ විදියටත් variable එකක් create කරන්න පුළුවන්. value එක අපි variable එක use කරන තැනදී assign කරන්න පුළුවන්. 

[data type] [variable name];

උදාහරණයක් විදියට ,

int counter;
counter=0;

Data type එක යොදන්න මුලින් අපි java වල තියන data types මොනවද කියලා දැනගන්න ඕනේ හරියට. Java වල variable types 3ක් තියනවා. Reference type, Array සහ Primitive type. අපි මෙතන කතා කරන්නේ Primitive types ගැන.  Primitive data types 8ක් තියෙනෙවා.

  • Integer Types (4)
  • Character
  • Floating Point Types (2)
  • Boolean
එක එක data type වලට වෙන වෙනම bit size එකක් තියනවා. 

Integer Types



Floating Point Types











Character සහ boolean සදහා bit 16 බැගින් තියෙනවා.

දැන් පොඩි program එකක් ලියමු.

public class mySelf{
public static void main(String args[]){

int age=23;
System.out.println("I am "+age+"years old");

}
}

මෙතන අපි age කියන එක + marks දෙකක් ඇතුලේ දාලා තියනවා. අපි String එකක් ඇතුලට variable එකක් embed කරනකොට මේ marks දෙක අතරේ දාන්න වෙනවා. 

දැන් run කරලා බලමු