Posts

Showing posts with the label Data types

Data Types in Java - සිංහල

Image
අද අපි බලමු Java වල තියෙන දත්ත වර්ග (data types) මොනවද කියලා. ප්‍රධාන වශයෙන් Primitive Data Types සහ Reference Data Types ලෙසට වර්ග දෙකක් ගන්න පුළුවන්. Java කියන්නේ statically-typed භාෂාවක්. Variables භාවිතයට ගන්න කලින් ඒවා හදුන්වාදීම(Declare) අත්‍යවශයි. මෙහිදී කලයුත්තේ variable එකේ නම සහ අදාළ data type එක සදහන් කිරීමයි. උදා:  int num ; Variable එකකට අගයක් ලබා දීම(Initializing)... ඉහතදී හදුන්වාදුන් variable එක int type නිසා මෙහි අගයද int type විය යුතු ය. උදා:  int num = 10 ; Javaහි Primitive Data Types 8ක් ඇත. byte short int long float double boolean char මෙම data types 8ට අමතරව  String data type එක ඇත. String ඉදිරිපත්කිරීමේදී ද්විත්ව  උද්ධෘත පාඨ   ( " " ) අතර ඉදිරිපත් කරයි. උදා:  String s = "string example"; අප String එකක් හදුන්වා දෙන විට ඉබේම(automatically) Heap එකේ String Constant Poolහි object එකක් නිර්මාණය වේ. String එකකට වරක් අගයක් ලබා දුන්පසු එම අගය නැවත වෙනස් කල නොහැක. ( immutable - නිත්‍ය ) එවිට තවත් object එකක...

Data Types in Java

Image
Today let's see what the data types in Java are. Generally, we consider two types of data types: Primitive Data Types and Reference Data Types. Since Java is a statically-typed language, variables must be declared before use. Declaring means you have to give the data type and name of the variable. ex: int num ; Initializing the variable... Since the data type of the above variable is int ,the value it contains should be an int. ex: int num = 10 ; There are 8 Primitive Data Types in Java. byte short int long float double boolean char In addition to these primitive data types Java also supports String type which contains character strings. Strings are represented within double quotation marks ( " " ). ex: String s = "string example"; When we declare a String, then an object will be created for it automatically in String Constant Pool of Heap. Once created the value of a String object will not be changed. ( immutable ) S...