Wealth Health java JavaScript Knowledge tutorial for beginners
This Tutorial site will help to learn Java ,JavaScript, Computer Science for beginners. we also covered bonus topics like Finance, Health and Hindu | Indian boys and girls name .
Switch statement is alternative and more cleaner way to write code if we have more than two options. we can use else if, this is better way. So lets start learning.
If you want to watch video tutorial for how to use switch statement in java simple click on below tutorial link.
Java Tutorial Switch Statement in Hindi
For illustration purpose we will use school grade example . we will male program if student get grade A we will print wow great job, if student get grade B we will print good job, if user get grade c we will print you passed, if user get grade f we will print , you failed and for any other grade we will print sorry you not appear . So lets get started.
First we will declare variable grade, datatype as char.
After that we will type switch and in the parenthesis we will pass our grade. and we will add curly brace. Now we will type case A and will print great job, and add break. It means in the grade if user get A grade then we will print this statement. Now we will add case B and we will print good job . and we will type break . Now we will repeat for grade C. Repeat process for grade F and add print statement. now at last we will add default it means any thing which is not mentioned in case , will fall in default and run that block of code.
Now in the grade variable assign A as grade and run program. In the result it will run block of Case A similarly try different Cases and check result.
If there is two condition we use if else but if condition is more than one? well we can use else if. So we will learn how else if condition is used in java with example. If you want to watch video tutorial about how to use else if in Java , below videos are available in English and in Hindi languages.
Here is scenario
Write Java program of where if food is warm print out food is perfect , if food is cold print "could you warm please" and for any other option print "I will wait"
Java Else if video tutorial in English
Java Else IF Statement Video Tutorial in Hindi
Now lets create class,
As we can observe in code we have created class name ElseIF and inside this class we created method name myElseIfMethod . We do not want to return but just would like to print as a result we are using void. In side curly brace we want to write our logic .
Now lets create variable and data type is string and name of variable is food and we set to warm for now . we will change it later to see how it will be in output.
Now we will use if condition so we use if and inside bracket we will specify our condition . In last tutorial we used double equal sign to compare and in this tutorial we are using dot equal to as shown in the code. we are comparing if food is warm then , system will run that block of code which is food is perfect.
But if food is cold then? we will write different logic for that . Now we will type else if and again in bracket we are specifying condition that if food is cold then we will print out please warm food
And other than that , we will print out I will wait . This is how if we have more than two condition we can use else if condition. You can change variable to cold , warm and other and check out put .
Code
public class ElseIF {
public void myElseIFMethod(){
String food= "warm";
if(food.equals("warm")){
System.out.println("Food is perfect");
}
else if(food.equals("cold")){
System.out.println("could you warm it please..");
}
else{
System.out.println("I will wait .....");
}
}
Now lets create object in main method . To create object on main method first type name of class then create provide name of variable and then equal sign , new and once again name of class and bracket. If you type variable and dot it will provide you accessible methods , select method which we created, run and check in the output.
If you want to learn more step by step java tutorial for beginners here is link .
In this tutorial you we will learn about how to use if else condition statement . we will use good example to understand how if else statement should created and to use it. If you would like to video tutorial on Java If else conditional statement, below is link in Hindi and English language.
Java If else video tutorial in English
Java If else video tutorial in Hindi lets create class in Java, As we can see we have created class IfElse and inside we have created non static method and we provide name as myIfElse and we use void since we are not returning anything. After that we typed bracket and in curly brace we will type our logic.
Scenario: If it will rain , instruct do not go out side and if it will not rain then print lets go out side . Make Java program using IF Else statement .
So lets make program . First we created variable and datatype as boolean. we set it as true it means , there is rain.
Now we type if, and we will type bracket next to it, we will provide condition inside. We set isRain == true. when we use = means we are assigning or setting value and if we use == it means we are comparing . So if there is rain we will run block of code ,which block of code ? it will print "Do not go outside". And if we set our variable to false then it will run "Lets go out side"
Since we set as true , it will print "Do not go outside code" . Lets check output. Click on Run and check our output.
If you change isRain to false it will run else block. Hope you understood concept if else in java. If you started learning java , make this kind of simple and easy program it will be fun . If you want more video tutorial click on this link and watch .
In this tutorial we will learn how to use Arithmetic Operators, Mathematical operations in Java. we will create separate non static methods for each operation like addition, subtraction, multiplication, and division and we call those in main method. If you want to follow along by watching below is link for java basic calculator where we have used arithmetic operation by creating method. Step be Step tutorial is in English and Hindi Language.
Java Basic Calculator Video Tutorial in English
Java Basic Calculator Video Tutorial in Hindi
For more video click on this link @amazingcodingtechworld
First create class and checkmark on public static void, so we can have main method .
Create method, in this example we created method Add and we use void since we are not returning anything. After method name we use parenthesis and then curly brace where we use our logic inside. we created variable named a and datatype is integer and hold value of 5. After that we have created another variable b which datatype is integer and hold value of 10. Since we are doing Addition we need result of both number that is why created another variable named result and we adding both number and we are printing it that is why we are using system.out.println as described in below image.
Now to call method in main class create instance of class . since we are using not static method we have to create instance of class. Syntax is name of class then variable then we use new word and class name then parenthesis. now if you use dot operator after that variable we will get all method which we can able to access. we want to use Add method so lets select it and check in output. we can observe we have result.
Now lets do Subtraction by creating non static method, we have created method and created variable , a, b, and result . All have data type as integer and we are calling in main methods.
Now lets try out multiplication everything is same but in the result variable we have just changed operation.
Now we are doing last operation, division. so we are doing same thing created three variables and calling in the result we have changed operation we are doing division and we are calling method in main .
In this java tutorial we will learn about how to create method and call method with example step by step . If you have any doubts you can watch java tutorial which is in English and Hindi languages.
Create method and call in Java in English Video Tutorial
Create method and call in Java in Hindi Video Tutorial
For more video click on this link @amazingcodingtechworld
Lets create class and and check mark on public static void so it will create main method, where we will call .
public class JavaMethod {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Now will create method in side class called Java method.
we have created myMethod and we use void since we are not returning anything and when we create method we give parenthesis() at will provide curly bracket . Inside out curly bracket we have out logic in this case we want to print "hello.....my method"
now to call this , in the main method we have to create instance of our class. so syntax is name of our class then provide variable name which is instance of our class and = new and provide class name. Now we have instance of our class now we can use it. if we type that instance and use dot operator we can access method inside our class and we can see out put as described in picture. This is how you use to create and call non static method. If you want to create static method you simple type name of method in main class.
In last tutorial we learn how to create class in eclipse and print hello world program. Now in this tutorial we will learn Java Data type step by step by practical example.
Like other languages java has different data type, context is same but there may be change in syntax and we will learn them one by one.
Lets create class, It the src folder right click and click on new provide name in this example we give name as datatype . checkmark on public static void main so it i will create main method in our class. and click on Finish.
Now check in editor , we can observe we have class name data Type and we have main method , we can ignore comment or remove it. If you want to learn by watching here is link of step be step video tutorial data type Java program for beginners in Hindi and English language. Please click on link.
Java Data Type Tutorial Video in English
Java Data Type Tutorial Video in Hindi
Data Type:
java Integer
In java we have to let system know what type of data type are we using. Lets start with int. we create variable , which hold data , so we will type int and we created variable name a and we store value of 5. so what is cool about variable every time we change value we do not have to change else where , we just use variable because it holds value. As we observe in below picture what would be output in console? you get it . it's 5 . click on green error button (Run) . but before that make sure you have saved it.
Console out put
Now what if you change a =10 and rerun program, what would be output? yes it would be 10.
Java Double
Now lets create another variable b , and set datatype integer and assign value as 1.5 (int b = 1.5) . Hmmm now we get error message now either we have to cast or we have to change type now change datatype as double instead of int , now you can see error is gone . it means if number is not whole we like 1.5 we should use double . now run program you will get out put as shown in below image
Java Character
Now it is correct time to introduce char, what would be best example? if teacher gives score to student like a, b, c ,d, f. we can use data type as char as describe in example , save it and Run.
Java String
If we would like to use sentence and would like to print it what datatype should we use? Answer is String lets see how to use string in java
we will type String as data type and we create variable which hold some kind of value and we assign as = sign. but unlike char we will use double quotation in string while in char single. In below example we created variable name and type of string which hold value(John) now save , run and observe in console. we get our correct value.
Java Boolean
Now we will learn Boolean . Boolean is true or false. And we can use boolean to declare value. In this example we have set boolean as true and we printed in console.
Why we have so many data types?
well these are not only the type there are byte, short, long, float etc . All have different size and capacity. If it is byte it would be size of 1 byte and can store whole number from -127 to 127. If we use short it will take 2 byte and we can store whole number from -32768 to 32767. If we use in as data type it will take 4 byte and can store number -2147483648 to 2147483647, for long it will take 8bytes and can store value from whole number -9223 372 036 854 775 808 to 9223 372 036 854 775 807.Now you can understand we can use same datatype for multiple thing but it will take more memory , that is why it is important to use wisely .
hope you like this tutorial if you would like to know more, please click on below link.
If you are new to any language we start with Hello World which is first step of learning .
If you have any drought or confusion there is step by step video tutorial in Hindi as well as in English about to start to learning Java by creating simple program of Hello World .
Pre-condition is first download code editor , like Eclipse https://www.eclipse.org/downloads/ . which will ease your work. Also you have to download Java based on your computer system. https://www.oracle.com/java/
Make sure you set Environmental variable . Or open command prompt by typing cmd in search bar. now type javac if you have few option as below it means you have set up correctly. there are lots of video about how to set up so you can follow that.
Video In English
Video In Hindi
open Eclipse or any code editor and click on File then Click on New
Now try to find java project if you can not find then select other project and type java and click on Java project , click on next
Enter name of Project and click on Finish
Now expand new created project and Right click on SRC, then New and Class.
Enter class name , and check mark on public static main and click on Finish.
Since we have check mark on Public static main system will create class with main method .
Now for print in console in Java we will type system.out.println and in brace we will type hello world since it is string will use string and semicolon after code which is compulsory in java. Make sure we will save , use control + S .
Now Click on Run and select First from drop down which is out class name if you have given something else make sure you select that name now check console.
Congratulation we have our first program of Hello World.