Friday, January 20, 2017

Learn Java for Beginner easily ! part 4 : Variables


So, the way I'm gonna teach you how to do JAVA isn't like a teacher at your school or your lecturer at college.They usually tell you about the theory first then the practice which makes you feel like "Why the hell am I here ?" during their explanation. I want you guys use your analytics sense more often.

The first thing I want you to do guys is to type the code on the picture below to your Eclipse or any Text Editor you have on your computer.



After you guys have finished, Run your program so that you guys can see the result.Now before I start explaining, I want you guys to observe the picture above.If you guys is new to programming world, then there must be a lot of questions in your mind.





Basically, variable is a place to hold somehing bigger,more complex,more complicated or longer in one place.This Variable that contains some complicated statements are stored in one place that you can name it as how you want it .In the picture above, I name my variable as "Bali".

Now look at the picture below.


You have to know that if you want to use Variables, Then you have to declarate it first so that the compiler will recognize the Variables.If you just directly type the value of a variables without declarate it before, then I'm sure your program is not gonna work.

Second, you must have realize that there is a word "double" before the name of my variable.
double is one of the data types of variable that you use to input a number either it's an integer number or decimal number.If you want your variables only contain an integer number, then use data type int before your variable's name.If you only want it with decimal number, use float.This is the complete list of datatype.


Complete Data Types List



You:  Why should I use Variables when I'm able to just type System.out.println("6.9"); ?

Me : Well, How if I want you to calculate 5,999 + 3,001+3,2+1,8 ?

You: Hmm I'm gonna use calculator to calculate it then put the result on the System.out.println          keyword so that it will show the result.

Me : No ! That's not how programming works.Use variables, so it's gonna be easier.I will show you how to do it in the picture below.




See ? It's simplier right ?

The last but not least, I want you guys to observe what is the difference between two codes below.

First code ;

Second code :

Why is the output printed in different way ? Have you guys found where are the differents between those two programs above ? If not, take a look in line 16-18 of those two programs then you will get it

So we can conclude that println is a keyword to make the next statement to be printed in the next line but print is a keyword to make the next statement to be printed in the same line.

So that's it.
If you guys have any questions about my explanation way, don't be hesitate to ask me on the comment column below.


No comments:

Post a Comment