Monday, January 30, 2017

Learn Java for Beginner easily ! Part 14 : Using method with parameters

What’s up guys ! Welcome back to my tutorials series.In this tutorial I will continue what I have explained in Part 13 about multiple classes. In the tutorial before (Part 13) I’ve explained to you guys about using a method of another class from your main class without any parameters (Empty Parameters). In this tutorial I’m gonna explain to you guys how to use a method from another class with parameters. What I mean by parameters is something you write inside the regular bracket after the method’s name.


As usually guys before I explain it further, I want you guys to type in both of codes below  :


1.First Code :


2. Second Code :



After you guys have typed both of codes above, I want you guys to run the program above from the main class.Next, I want you guys to input a text in the console box underneath your program. In the first picture above, I input my name. My name is the one with the green text , then the input that you have stored will be showed as how it’s declared in the second program. In this case, the output is “Hello Irsyad Ashari” and I will explain to you guys why. Listen up and pay attention .

First program :
Line 1 :
I have explained this code in Part 5, check it in the Line 1 there.

Line 3 & 5 :
I have explained this code in Part 2. Go check it out if you still confuse about it.

Line 7 & 8 :
I have explained this code in Part 13. Go check it out if you still confuse about it.

Line 10 :
I don’t think I still have to explain it anymore.You guys have got this code for like a thousand             times.

Line 11:
String name = input.nextLine ( );

what's the code above means ? the "String name" is the declaration of a variable called          
            "name" in string datatype. and the rest (= input.nextLine( );) means that every data that you                 input will be stored in variable "name" using the "input" scanner utility.  The ".nextLine( )"                 means that the data that you will input will be in a string format. You guys have learn this                     kind of code in the couple of tutorial parts ago.

            Line 13 
simpleObject.message(name);             
                
            simpleObject means that you are gonna use the "simple" class from your main class.
            .message(name); means that you are gonna use the "simple" class with "message" 
            method using the value of the "name" variable.

Second Program :

            This code contains a class called "simple" with a method inside it named "message".
            There are also a code to print out "Hello"  followed with the data inside variable "name" .

So that's it guys for now. Thank you guys for visiting my blog, hope you guys enjoy it and see you on the next tutorial. If you guys got something to be asked, please leave a comment below and thank you very much.

Greetings from Programmer !

No comments:

Post a Comment