Argonz's Weblog

My Personal Weblog

Java : Lesson 002 Flow Control 1 (if)

Posted by argonzdcc on November 10, 2009

Hi guys..! We will continue our lesson, before I have posted lesson 001 as warming up our lesson. May be some of you ask me why didn’t the lesson explain about basic programming like structure programming, variable definition, type data, consept of object oriented ect. I answer that this lesson for us who have studied about programming and who want to know form programming of java. But if you want to ask about that (type data, etc) we can discuss about that. Just comment me and I will try to reply you. Okay guys.. Lets start our lesson ..!!

Explanation :
I will explain line by line that I haven’t explained before, so if you want see explanation line that I don’t explain here, you should go to lesson before.
Line 3 : char firstInitial= ‘a’;
We made identifier with type data char and the name of identifier is firstInitial and we put ‘a’ as first volume for this identifier.

Line 5 : Try {
It is we use for dislocate mistake to the exception, we can show the exception or not. It depend us
Line 6 : firstInitial = (char)System.in.read();
It’s a metode to input one character. We will input one character into firstInitial.
Line 7 : }catch (Exception e){
The pair of Try is catch. Catch is to take the mistake and get in to Exception and Exception here have identifier is ‘e’
Line 8 : System.out.println(“Error : ” + e.toString());
This is an inctruction to show exception if we have.
Line 10 : if (firstInitial == ‘a’)
This is what we called flow control, and for this listing the condition is identifier firstInitial equal or contain character ‘a’.
Line 11 : System.out.println(“Your name definite Asep !”);
This is an intruction to show the text if the condition is identifier firstInitial is ‘a’
Line 12 : else if (firstInitial == ‘b’)
This is a second condition, the condition is identifier firstInitial equal or contain character ‘b’
Line 13 : System.out.println(“Your name definite Bambang !”);
This is an intruction to show the text if the condition is identifier firstInitial is ‘b’
Line 16 : else
It’s the last condition, the condition is whatever character except ‘a’ and ‘b’
Line 17 : System.out.println(“Your name is not famous !”);
This is an intruction to show the text if identifier firstInitial isn’t equal or contain ‘a’ or ‘b’

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>