Tuesday, November 23, 2010

Java Tutorial #1

0
This site will link some of the useful and beginner oriented videos on youtube to help you on your studies.  Hope this help.  Now you have your main class created, you can now start typing codes to your program.  In our Computer Programming Class, our introductory topic is all about JOptionPane.  Most codes of the Java are originally came from C++ or some of TurboC.  So, some of my classmate didn't find Java as hard as they expected it will.  But for some considerations to those who are not yet taken either the TurboC or the C++ let me give some ideas of the TurboC and the C++ as far as I know it.  So lets get started. Let me start the topic to Basic Output Process of the Program.
Example: This program will output the value of a variable as you initialize it.

What you must know first?


Different Class Specifiers in Turbo C:
Data Type    Control String           Definition                 Example
Char               "%c"                used for ouputting a               'W' or 'p'
                                               letter or a symbol.


Char                 "%s"               used for outputting two          'Yes!' or 'Pie'
                                                   letters or symbols.


int                    "%d"            used for outputting integers.      '56' or '12'

float/double      "%f"             used for outputting numbers      '5.2648'
                                                  with decimal places.




Note: This Program will shows the difference between println and printf statement.

By using printf:


It is will ouput the number and some unnecessary zeros showing that it is a double/float specifier.
You can limit the variable's decimal places by adding a decimal point and a number to the control string. ex. " .2%f" will display a float number with 2 decimal places. You can change it to 3 or so on.

By using println.






It will output the value of the variable the way you exactly assigned it.  No unnecessary zeros at so on.

No Response to "Java Tutorial #1"

Post a Comment