Posts

Showing posts from May, 2015

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

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 සහ fields කියන්නේ එකම ද නැත්නම් වෙනස් ද කියලා ප්‍රශ්නයක් ඇති.Local variabl

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             variable is the parameter to this method. And constructors also take parameter variables as                   arguments.

Hello World Java

Image
First, let's see how to run a Java Program using a text editor like Notepad and command prompt and after that let's move on to the NetBeans I.D.E. Java is an Object Oriented, High-level programming language and a computing platform which was released by Sun Microsystems in 1995. An important feature of Java is, it is platform independence. (Platform Independence means once a program is compiled then it can be run on any platform such as Windows, Mac OS X and Linux. ) To run Java on your machine you have to install Java Development Kit  (JDK). You can download JDK and NetBeans  from this link . When you download JDK, you get the Java Runtime Environment(JRE) which consists of Java Virtual Machine (JVM), Java core classes and Java libraries. And we have to set the Java bin path to the path variable. 1st Step :     C Drive -> Program Files -> Java -> jdk -> bin-> copy the path . (when you click on the bar with the folder icon which contains the folder

Hello World Java - සිංහල

Image
මුලින්ම අපි notepad වගේ text editor එකක් සහ command prompt එක use කරලා අපේ පලවෙනි Java program එක run කරමු. පසුව NetBeans I.D.E. එක use කරන ආකාරය බලමු. Java ගැන පොඩ්ඩක් කතා කලොත් Java කියන්නේ Object Oriented, High-level programming language එකක්. Java ක්‍රියාත්මක කරන්න ඔබේ පරිගණකයේ Java Development Kit  (JDK) install කර තිබීම අත්‍යවශයි. JDK හා NetBeans   මේ ලින්ක් එකෙන් download කරගන්න පුළුවන්. JDK download කරගත් විට Virtual Machine (JVM), Java core core classes සහ Java libraries අන්තර්ගත වෙන Java Runtime Environment(JRE) එක ඔබට ලබාගැනීමට පුළුවනි. Java  ක්‍රියාත්මක කරන්න නම් Java bin path එක path-variable එකට set කරගන්න ඕනි. 1 පියවර :   C Drive -> Program Files -> Java -> jdk -> bin-> path එක copy කරගන්න . (folder icon එකක් එක්ක උඩින්ම මේ path එක තියෙන line එකේ click කලාම path එක copy කරගන්න පුළුවන්) 2  පියවර : Computer -> Properties -> Advanced system settings -> Environment variables... -> select 'path' variable in System variable