1 00:00:01,860 --> 00:00:04,560 In this lecture, I'm going to talk about variables. 2 00:00:05,100 --> 00:00:07,080 OK, so what are variables? 3 00:00:07,620 --> 00:00:15,270 Variables are used to store information, something like a number letter, a sentence or a combination 4 00:00:15,270 --> 00:00:15,810 of these. 5 00:00:16,510 --> 00:00:19,970 It is a piece of memory segment where the data is stored. 6 00:00:20,490 --> 00:00:25,220 First, we're going to look into the declaration and definition of a variable. 7 00:00:25,740 --> 00:00:28,950 So how to declare a variable and what it means. 8 00:00:29,430 --> 00:00:32,850 So to declare a variable in Java is the following. 9 00:00:33,330 --> 00:00:40,680 You need to type and data type first, then the variable name and a semicolon to the end of the line. 10 00:00:41,310 --> 00:00:43,490 We don't assign any value to it. 11 00:00:43,500 --> 00:00:47,210 Here, let me show you how it works in practice. 12 00:00:47,550 --> 00:00:49,740 So we created this program previously. 13 00:00:50,100 --> 00:00:53,670 Now let's delay the system that outdate print and online here. 14 00:00:56,470 --> 00:01:08,050 And instead, Tiepin and a number of followers and a semicolon, this variable can represent a number 15 00:01:08,050 --> 00:01:13,860 of YouTube or Twitter followers, or we can use another name like number of countries. 16 00:01:14,260 --> 00:01:16,860 And here is used for whole numbers. 17 00:01:17,440 --> 00:01:24,220 As you can see, the variable name is great because it isn't used and it doesn't have a value. 18 00:01:24,700 --> 00:01:31,600 So how we assign a value to this variable, that's what is called definition. 19 00:01:32,080 --> 00:01:33,110 It is very simple. 20 00:01:33,610 --> 00:01:41,040 First, the data type than the variable name equals and value we would like to assign to the variable. 21 00:01:41,500 --> 00:01:43,990 And finally, a semicolon to the end of the line. 22 00:01:44,740 --> 00:01:54,080 Or we can first declare the variable and then you type in the name and equals the value and a semicolon. 23 00:01:54,740 --> 00:01:57,130 OK, how it works in practice. 24 00:01:57,580 --> 00:01:59,760 I'm going to show you the second case here. 25 00:02:00,190 --> 00:02:05,560 So and enter here and number of followers. 26 00:02:06,900 --> 00:02:11,310 And intelligence offers us the variable name Anta. 27 00:02:13,290 --> 00:02:21,010 And then equals and one hundred and ninety five and a semicolon here as well. 28 00:02:21,910 --> 00:02:32,350 The other option is to define it in one line, the easiest way to do that is to delete this here and 29 00:02:32,350 --> 00:02:32,890 that's it. 30 00:02:33,710 --> 00:02:39,470 Both correct, but the second one is used one, we don't know the value of the variable at the beginning, 31 00:02:39,650 --> 00:02:41,600 but we will calculate it later. 32 00:02:42,700 --> 00:02:50,050 OK, so what data types Java has, there are two groups, primitives and object references, there are 33 00:02:50,050 --> 00:02:52,690 separate lectures to explain them in details. 34 00:02:53,020 --> 00:02:56,130 But I'm going to give you a short introduction to them here. 35 00:02:56,680 --> 00:02:58,540 So let's start with primitives. 36 00:02:59,230 --> 00:03:03,880 Hole number data types are Boit, short end and long. 37 00:03:04,660 --> 00:03:11,320 They are very based on how big number they can store in here is bold because it is the default data 38 00:03:11,320 --> 00:03:12,760 type of whole numbers. 39 00:03:13,390 --> 00:03:20,320 They can be used to store whole numbers like number of players on the field or number of passengers. 40 00:03:21,160 --> 00:03:23,670 The next group is floating point numbers. 41 00:03:24,280 --> 00:03:28,090 There are two types float and double here. 42 00:03:28,090 --> 00:03:29,610 Double is the default value. 43 00:03:30,340 --> 00:03:34,840 They also vary based on how big and precise numbers they can store. 44 00:03:35,530 --> 00:03:40,320 They can be used to store bank account balance or transaction amount. 45 00:03:41,290 --> 00:03:46,600 The next group has only one type boolean which can have two states. 46 00:03:46,600 --> 00:03:54,670 True or false, it is a simple one and a good option to store values like Willett's now tomorrow, true 47 00:03:54,670 --> 00:04:00,520 or false, and the last one which can be used to store one single character char. 48 00:04:01,180 --> 00:04:07,480 It can be used for storing the energy efficiency category of a refrigerator or washing machine. 49 00:04:08,860 --> 00:04:11,690 OK, now let's move on to object references. 50 00:04:12,400 --> 00:04:18,430 They are a bit different from the primitives I mentioned in the introduction section that Objects has 51 00:04:18,430 --> 00:04:22,240 a state or states and also have behaviors. 52 00:04:22,630 --> 00:04:26,710 Primitives doesn't have that kind of functionality that objects has. 53 00:04:27,220 --> 00:04:33,000 There are many object reference types and primitives has that object reference versions as well. 54 00:04:33,460 --> 00:04:38,190 So whole numbers, byte short, integer and long. 55 00:04:38,710 --> 00:04:45,700 They are almost the same, except that they are all start with uppercase and instead of end here we 56 00:04:45,700 --> 00:04:54,160 have integer uppercase here shows that these types are object reference types and you will see all object 57 00:04:54,160 --> 00:04:56,680 types start with an uppercase. 58 00:04:57,280 --> 00:05:00,990 OK, now let's move on to floating point numbers float and double. 59 00:05:01,450 --> 00:05:02,590 Nothing special here. 60 00:05:03,310 --> 00:05:06,710 Also, Boolean has its object reference version as well. 61 00:05:07,540 --> 00:05:11,860 What is new here is the text types instead of char. 62 00:05:12,100 --> 00:05:20,680 We have a character with uppercase which can do the same thing for a single character and a new data 63 00:05:20,680 --> 00:05:26,290 type string string can store almost unlimited amount of text. 64 00:05:26,740 --> 00:05:33,160 It can be used to store sentences, descriptions, titles, basically any kind of text. 65 00:05:33,880 --> 00:05:38,110 The last group here is the built in and custom object references. 66 00:05:38,590 --> 00:05:46,060 It can be a five right, which can be used to modify a file or system that we used in the first Java 67 00:05:46,060 --> 00:05:53,650 program lecture that blue ware can be the name of a custom object in a game or an ATM machine for a 68 00:05:53,650 --> 00:05:54,700 banking system. 69 00:05:55,360 --> 00:06:00,940 So besides these inbuilt object reference data types, we can define our custom ones as well. 70 00:06:01,810 --> 00:06:07,990 In the upcoming videos, I'm going to show you how to use primitives, how to use object references 71 00:06:08,170 --> 00:06:11,920 and how to define and use your own custom versions. 72 00:06:12,430 --> 00:06:17,230 But before that, I would like to tell you more about the naming conventions of variables. 73 00:06:17,800 --> 00:06:19,800 So variables are case sensitive. 74 00:06:20,200 --> 00:06:26,170 For example, if you would like to use a variable, you need to type in exactly the same name Binya 75 00:06:26,170 --> 00:06:26,920 declared it. 76 00:06:27,460 --> 00:06:33,790 The next one is that typically variables cannot be declared two times with the same name in the same 77 00:06:33,790 --> 00:06:35,830 class or in the same method. 78 00:06:36,310 --> 00:06:43,540 Also, variable name must start with a letter or dollar mark or underscore, but I don't recommend you 79 00:06:43,540 --> 00:06:46,030 the last two after the first letter. 80 00:06:46,120 --> 00:06:49,750 It can contain numbers, but it isn't recommended either. 81 00:06:50,020 --> 00:06:54,930 And last here, variable names cannot be equal to reserved keywords of Java. 82 00:06:55,660 --> 00:07:04,510 Here you can see a list of the reserved keywords abstract continue for new switch and the list goes 83 00:07:04,510 --> 00:07:04,770 on. 84 00:07:05,410 --> 00:07:07,450 You don't need to memorize these Java. 85 00:07:07,450 --> 00:07:11,440 We warn you that you cannot use these words as variable names. 86 00:07:11,980 --> 00:07:17,500 You might think this list is very long, but don't worry, I will explain all of them later in the course. 87 00:07:18,160 --> 00:07:22,390 One last thing I would like to share with you is the naming standards and business. 88 00:07:23,110 --> 00:07:27,520 These are not forced by Java and it is not necessary to follow them. 89 00:07:27,820 --> 00:07:31,180 But they can make your code more readable if you stick to them. 90 00:07:31,510 --> 00:07:38,260 Also, if you apply for a job and you apply these recommendations, it will show the interviewers that 91 00:07:38,260 --> 00:07:41,230 you are familiar with the business naming conventions. 92 00:07:41,750 --> 00:07:43,960 The first point is Camil case. 93 00:07:44,470 --> 00:07:51,970 So the variable names first word should start with lowercase and every other word in the variable name 94 00:07:52,210 --> 00:07:57,640 should start with uppercase, like I did with number of followers. 95 00:07:58,090 --> 00:08:02,110 No lower case than of with uppercase and follower's. 96 00:08:02,110 --> 00:08:03,280 With uppercase to. 97 00:08:04,240 --> 00:08:09,410 The next one is that the variable names should fully describe what the variable contains. 98 00:08:09,670 --> 00:08:17,500 So don't name the variables like X, Y, Z or A or B or C instead is meaningful names. 99 00:08:18,160 --> 00:08:24,820 If you go back to your code a week later, you will hardly remember what A or B or C means. 100 00:08:25,750 --> 00:08:32,680 The following point is that do not use abbreviations if you can avoid them, use long variable names 101 00:08:32,680 --> 00:08:33,310 instead. 102 00:08:33,970 --> 00:08:39,490 OK, the next recommendation is that do not reduce the variable names for other purposes. 103 00:08:40,120 --> 00:08:46,210 For example, do not use the number of followers variable to store number of notifications. 104 00:08:46,630 --> 00:08:49,240 Create another variable for that instead. 105 00:08:50,080 --> 00:08:56,390 And the last one I mentioned before, do not use Tollerson or underscore in the variable names. 106 00:08:57,260 --> 00:08:59,470 OK, that's pretty much it. 107 00:08:59,980 --> 00:09:01,330 See you in the next video. 108 00:09:01,330 --> 00:09:03,550 But I will tell you more about primitives.