 Hi everyone. In this video, we'll be taking a look at how to create a new project in Eclipse, more specifically a new Java project. So we assume that you have installed Java Standard Edition and you have installed Eclipse IDE for Java Developers. The current version of Eclipse is 2020-12. So make sure you have the latest version installed because it does matter when it comes to JUnit testing. We go to workbench on the top right corner and that takes you to the project area. You can click on create a Java project straight away or you can click on file, meme and Java project. You will see that the standard edition for Java that I'm using is 14. If you download the latest one, that's 15.0.2, it will show Java SE-15. By convention, project names begin with a lowercase letter and our camel case, which means first letter of every subsequent word starts with an is an uppercase letter. Click on finish and when it asks you to create module info.java, click on don't create. So don't create that. And that's your project, which references the library used and the source folder, which is currently empty. This is where we put all our Java files. So you can right click on the source folder and choose new and class. We can name our class client or we can call it my first Java program. As you can see here, by convention, class names begin with an uppercase letter and our camel case as well. And that's all you have to do. If you want your class to be an executable class, which means it should be able to run as a Java application, you have to choose on public, static, void, main, string, array, ARGS. This is equivalent to setup in processing as a or the main method in C++. So you finish this and you can see it automatically creates what's a package inside the source folder. So Eclipse has this convention where it creates a default package with the same name as the project name, adds that package declaration to say that this class belongs to that package. It contains a public class, my first Java program, and inside the class, the main method of function inside the public class. And all your code, except new function calls, obviously, all your code goes inside public, static, void, main. So we're going to write a very simple program here, which checks if a number is positive or not. So I'm going to write over here, let's take a number like 23, enter the number like zero, and a third number like minus seven. I would like to determine if these three numbers are positive. It gives you these yellow bulb signs, which are warnings. And the best thing you can do in Java and Eclipse is just make sure that you pay attention to warnings and errors, and carefully read the error or warning messages. So it says over here the value of local variable C is not used. Okay, we're not using it right now, but we will use it in future. So checking if a is positive. Now positive means more than zero. We'll also have three variables in which we'll check or hold the status of whether these variables are positive or not. If a is more than zero, yes, it is positive. Otherwise, no, it is non positive, which means it could be zero or it could be negative. So we say status A becomes true. And otherwise, status A becomes false. And we're going to display this status. So you can see that the warning has gone from int A equals 23. And we can say A is positive. And the answer is the status value. Okay, let's run this. And running is done using this play button. And you can see in the console, a nice little message 23 is positive is true appears. I can move the console to the right as well. I can remove coverage. You can configure the view as you want. And again, don't panic if the view changes and you close accidentally something, you can always go to window, show view, and show whichever view you have hidden. Now, basically, we are doing the same thing for B and C. So I can copy this code and paste it again. And I can copy this code and paste it again one more time. You can see that the indentation has become weird and the variable status A has been cleared multiple times. Obviously, you can change that. To fix indentation, you can press Ctrl A and Ctrl I on windows or Command A and Command I on Mac. So we change status B, status B, status B, it's B that we are checking, is B positive, that status B. Then we have status C is C positive, then status C and status C and C. So obviously, when you copy and paste, you have to make sure that you make changes everywhere. When I run this, you can now see that 23 is positive is true, while 0 is positive is false and minus 7 is positive is false as well. But obviously, you can see that this code is very poor because this piece of code is doing the same thing three times. So what we can do is we're going to create a function instead of this. I can get rid of the code that does the repetitive work and the code that does the actual work. I'm going to put it in a function. You already have this function void main. So this is, I'm talking in terms of comp 1000 language, you have a function void main. The public static is extra. I can't explain why it's static right now. Just assume it is and we're going to move on with that. So what you do is you add another function, public static, boolean is positive and the parameter is an integer value, which is value. So I'm defining a function that returns true if the past value is positive and false otherwise. Just over the function, if you put slash star star and press enter, you can see that it generates this at parameter. This is an annotation and at return, which is an explanation of what it should return. So return true if value is positive and explain what is a positive number more than zero false. And the same logic here, if value is more than zero, return true, else return. And notice that intentionally I didn't put curly brackets around my if and else, but that's fine because both my if block and my else block have a single statement. So I don't really need curly brackets. Once I have defined my function, I can say boolean status A is the value returned by is positive function when the value A is passed to it. Similarly, status B and C are the values written by the function is positive when B and C are passed to it respectively. And you can see our program is much cleaner now. When I run the program, it gives you the same output, which is great. Another way in which you can make the program more compact if you only need these values once is by directly invoking them inside your display statement. So I can get rid of that and get rid of this. If I run that program, I get the same answer. And as I said, if you only need the values of A, B, and C to check if they are positive or negative, then you can call the function by passing the constants without declaring the variables. But since here I need A, B, and C to be displayed, you can see that I cannot do that or I have to change 23 at both places. So let's do that. So that's your basic program. Now, let's say I would like to determine the sum of the first 10 integers. Then I can say, okay, sum is initially zero. I'm intentionally making a mistake here, by the way. Sum is zero. And I can go for the first 10 positive integers. Sum increases by that current number. And we can display sum. You will see that the first error appears on line 13, where it says syntax error on token semicolon, curly bracket expected after this token. So over here, curly bracket. So this is not very helpful. What's happening is this piece of code that I have, this piece of code that I have, it lies outside any function. So following piece of code doesn't belong in any function. It's sitting outside all the functions and that is not allowed. That's the mistake that we are making over here, which means that I should get rid of that and move it inside my main function if I want to execute it inside the main function. So, and I can say over here, sum of the first 10 integers, positive integers, the first 10 positive integers is sum. When I run this piece of code, and you can see why sometimes you want to move your console around based on the width of your output. So I say sum of the first 10 positive integers is 55, but if I check 100 and change 100 here, it's 5050. The sum of the first 1000 integers is 51500 and so on and so forth. We can also calculate the sum of all integers in a range. So from 43 to 128, and you can change here, sum of positive integers in the range, 43 comma 128 is this. So that's me using some conditions and some loops and defining a function in Eclipse. One more thing I would like to mention over here in this function is this is a Boolean function. Now, if I put curly brackets around this, you have an if-else block. Val more than zero is the Boolean expression that guides the condition block. If my control reaches line number 26, what's guaranteed is that yes, in fact, val is more than zero. But if it reaches the else block, what's guaranteed is that val is less than or equal to zero. Well, let's think about that if I didn't use the else condition. What if your code reached line number 30? What do you think is guaranteed? Val was in fact more than zero. It would have entered the conditional block and it could have returned the value, which means that line number 30 would never be executed if val was more than zero. So I can safely say that it's guaranteed that val is less than or equal to zero if it reaches line number 30, because otherwise the function would have exited with the value true. And because this is guaranteed, you can return false unconditionally. So this is a very nice way in which you can make a Boolean function compact when it's a very trivial Boolean function where it checks if something happens written true, otherwise return false. One more thing. Let's say the value of val is 23. What's the expression 23 more than zero 23 more than zero evaluated to 23 more than zero, the Boolean expression is true. So when that Boolean expression is true, I am returning true. So please keep that aside when val more than zero is true, we return true. Let's take another example where val is either zero or minus seven. What is minus seven more than zero evaluated to that Boolean expression is false. Similarly, zero more than zero is also false. When that val more than zero evaluates to false, we do not execute the conditional block, but we return false. We skip the conditional block and we return false. So when val more than zero is false, we return false. So you'll see that what we are returning is we are actually returning the outcome of the Boolean expression val more than zero. So that's another way in which you can make your simple Boolean functions very compact by returning simply the outcome of your Boolean expression. Let's run this and you can see it still gives you the same answer. I really like this way of programming because a lot of times when things are trivial, it's better to make it compact and move ahead with other stuff. But it's a very subjective view. Some people agree with me. Some people don't. You decide what you like best and stick with me. Thank you very much for watching this video and hope I see you soon. Take care.