 Hello friends, I am Sanjay Gupta. In this video, I'm going to demonstrate you how you can add two numbers in Java. So first I'm writing the code in Java, then I will be executing this code so that we can check whether the program is working properly or not. First of all, in Java, whenever you want to implement any particular logic, you have to implement that logic inside a class. So here name of class is some inside this class, I'm going to write main method. So you can see I have implemented a block for main method. It will receive command line arguments in ARGS string array. Its written type is void. It is a static method which will be called automatically whenever I will be executing this code. Now inside main method, I have to implement the code which will perform addition of two numbers and those numbers will be provided by the user. So I have declared three variables and one and two and three. Now I have to receive input from user for that purpose. I have to use scanner class. So I'm going to import a package Java, sorry import Java dot util dot scanner. So util is a package and inside that package scanner classes be implemented or predefined. So I'm going to use this scanner class. That's why I have imported this package or class. Now I'm going to create instance of this scanner class and I have passed an argument in instance of this scan class that is system dot in. So this input will be receiving all the inputs from the command prompt or you can say console. Now I'm writing a statement system dot out.println and it will display masses and the first number on output screen. So this message will be displayed after display of this message user will be providing a number. So I'm going to read that number inside and one variable through input dot next in. So here you can see I have used next in. So this next in is a method which is pre implemented in scanner class. So I have created instance of scanner class that is input. So through input I can call next in method to read input input from user. Now I have to read another number. So I'm copying line number eight and nine. I have pasted those lines and I'm modifying the masses and the second number and in place of N1 I'm writing N2. So this way I am able to read two numbers from user. Now I have to perform addition operation. So this is a simple addition operation and three equals to N1 plus N2. Now I have to display output on output screen. So again I'm using system dot out dot brain talent the masses some equals to will be displayed and the value of N3 will be displayed for separation. I'm using plus operator. So this way I have implemented the complete code for adding two numbers in Java. This is the simple program and this is the very first program of Java that you can implement in your system to understand how we can receive input and how we can perform addition and print the result on output screen. Now after implementation I have to save this code. So I'm pressing control S moving to D drive in D drive. I have a folder Java inside this Java folder. I'm going to save this program with some dot Java. So always remember that whenever you save your program you prefer name of class because after compilation byte code will be generated and all byte codes in Java will be generated with the name of class. So prefer name of class as source code saving. Now I have to execute this code. So I'm opening command prompt. You can see command prompt has been opened. Now I am moving to D drive inside D drive. I have to enter into Java folder. Now inside Java folder this sum dot Java file is present. So first time compiling this code with Java C space sum dot Java. So Java C is the command for compilation. If there are any errors it will be displayed on command prompt. Otherwise you can type next command. So here no error is displayed so I can execute the byte code which is generated. So let's see first byte code. So I have typed DIR command so it will display a directory or the files which are available in Java folder. Here you can see there are two files sum dot Java that I have created as source code and some dot classes created automatically just after the compilation. Now I can run this sum dot class file by typing Java space sum only. So this is the command for executing Java code. You can see it is asking for first number. I am entering 10. It is asking for second number. I am entering 20. You can see the result. It is displaying sum equals to 30. So this way you can see I have able to add two numbers which are provided by the user and I am able to see their sum on output screen. So this way you can add two numbers in Java. I hope you have understood how we can add two numbers in Java. If you want to watch more programming related videos you can subscribe my YouTube channel. Thank you for watching this video.