Java Tutorial For Beginners – 5 – Basic Data Types

Hey everyone welcome to the fifth tutorial on Java programming for beginners in this tutorial we’ll see what data types in Java are remember in the previous tutorial we used a word string before the name of the variable let us understand why we use this word here with a simple example according to the Java rules the minimum that we.

Need to do to declare a variable s to mention the name of that variable and the data type of that variable there is the type of data that the container will contain for example if you want to store a number.

Without a decimal point the type of variable that you should be using is in teacher so for integer just say int and then the name of the variable so.

Let us name this as number and here you’ve declared it so this is the minimum that you need to do at this point if you further want to initialize that is assign a value to this variable right at this point you can say equals a value so nth number equals to 5 similarly if you want.

To store a number with a decimal point there’s a data type known as double for it so if you try storing it here say five point six Java won’t accept this because it says.

Required int found double the course you tell Java that the variable is of type integer it will expect you to assign an integer to Wed so for five point.

Six let us use another devil takes values with a decimal point just like in the previous example we stole the value of Pi which is a decimal number and the variable named PI supply equal to three point one four and this works because we’ve mentioned the data type of this variable as now.

Say you want to store your name into a variable so the data type that you should be using to.

Store a name is string same string name equals Alex so your name is a sequence of characters that is a shrink of characters that is why you should be using the data type as string if you try doing.

Something else Java won’t accept it because it will now be expecting an integer from.

You that is why it’s required integer found string similarly if you want to store.
A single character say only the.

Initial of the first name a you can use a string but a better way to do this would be to use and character data type because a string will require more place into the memory then a single character so you can say care me equals a now this does not work because to initialize characters you need to have them.

Into single quotes so single quote a and Java would accept it also do remember that while.

Of value to a variable of type character you have the value in single quotation marks because a character variable contains a single character similarity.

When you are working with string datatypes you should have the value and double quotation marks because this will contain a sequence.

Of characters and when you are working with datatypes related to numbers such as variables of data types integer or double you just assign the numerical value directly to it without using any quotation marks for example say int number equal to 5 so this was a simple introduction to some basic datatypes in java we will look at more data types as we proceed with this course for now we will end this tutorial here thank.