Saturday, November 27, 2010

Java Tutorial #7

0
The Java's Scanner


Java Scanner is used to store variables and string you inputted in the console.  For example, the program requires you to put/type any number.  The string or the number you inputted in the console is being stored by the the Scanner.  So that later your program can access the data you inputted.  In able to use the Scanner you must import it to your Program (at the top part of your program see the first picture below) just type "import java.util.Scanner;".


Now, you have imported the Scanner in your program, you can now assign a name into that Scanner just type the word "Scanner scannername = new Scanner(System.in);". Note that you can have any name for the scannername.  Any character is qualify for a ScannerName.  


Now, we created a new Scanner.  The question is how we can access the data inside it.
In order to access information inside that scanner, first call the variable you stored to that scanner, put the equal sign then second put the scannername ,put the dot symbol (.) and type one of the ff keyword 

nextLine( );  --->  If variable is a String or a Character.
next( ); ---->  If you want to leave the cursor the last letter of the String.
nextInt( ); --->  If the variable is an Integer.
nextDouble( ); --->  If the variable is a float/double Value.

(ex. variable = scannername.nextInt( ); if the variable is an Integer)

For example, a program that will ask you to enter your name and then it will output the greeting "Hello " plus your name.  Later, your name will be stored in the Scanner then the program will access/process the information you inputted and add the word "Hello  " to it. Consider this example.


Java Tutorial #6

0
More of Math Class Function in Java Programming

Build in Function for Ceiling and Floor Value
  Math.ceil(value); , Math.floor(value); is the reserved words for finding the ceiling and the floor value.  This is also known as nearest value function.  This can find the nearest up and down value of a number.  Consider the example below.

Build in Function for Power
   One of the commonly used function in Java is the Power function.  Usually used for exponential functions and inverse function mainly concerned for trigonometry functions.  Math.pow(base, exponent); is the reserved word for it.  See example below.

Build in Function for Square Root
    Also the same with the Power function this is one of the easiest yet most applicable function widely used today.  Mainly this is concerned for different mathematical computation.  Math.sqrt(value); is the reserved word for it.



You can now explore some of the Math class by using them one by one. Hope this topic helps you out.

Java Tutorial #5

0
Different Math Class in Java


This topic will include multiple Math Class Function that is very applicable to Java Programming.  There are so many Math Class Function to Java Programming but I will only mention some of it (The Function that very commonly use to some applications).  So, Let get Started.

Build in Function for PI = 3.1416;
   Math.PI*value is a reserved keyword in Java.  This keyword will automatically initialize the nearest value of PI.  This is commonly used keyword for finding the Area, the circumference, and volume of different circular figures.  Consider the first bunch of codes in the program.

Build in Function for Absolute Value
    Math.abs(value) is also a reserved word in Java Programming. This keyword will automatically omit the negative signs to your integer.  It will convert the negative integer into positive.  Look for the second group of codes inside the program below.

Build Function for Maximum and Minimum
    This Function will take two arguments.  The two value you want to compare.  You can assign the value to a variable or you can directly type it.  Math.max(value1, value2) for maximum and Math.min(value1, value2) for minimum.



Java Tutorial #4

0
The .replace( ) Function in Java


This is one of the easiest yet the most commonly used keyword in Java.  It is used to replace a character or a group of String to an existing String.  This function will take two arguments.  The first argument is the OLD CHARACTER you want to replace with.  The second argument is the NEW CHARACTER/WORD that will replace the old/existing group of String/character.

START------->
Consider this example.  Like I said a while ago, this is one of the easiest function so I don't have to spend more word for it.  The explanation is the comment inside the program.  Read those green lines then later you will get it.




I hope you get it. For questions,  you can put it to the comment box below this one. Thanks.

Friday, November 26, 2010

Java Tutorial #3

0
The toUpperCase() and the toLowerCase() Function in Java

The two functions is use to output or to display a string in a Lowercase or in the Uppercase. So, Let us make use of it..!

START------>
I think it is a SELF EXPLANATORY FUNCTION so I will not spend more time to it.  I will show you some example then BOOM you will come up to the I GET IT state. 




Java Tutorial #2

0
The Two ways to do a Process of Concatenation
This article will show you the two concatenation process available and valid to Java.  One way is by using a symbol "+" and the other way is by using the ".concat( )" method.  You will later know what is the difference between the two.

START----->

The "+" symbol is using by the concatenation operation.  It is use to concat (combine) two strings, variables, characters and others. In the previous program we make sense the use of the "+" symbol.  We use the "+" symbol the combine the string "n1 is " and the value of the variable n1.  (We don't want to spend more time hark backing some things that uses our very important sense , the common sense.) Now, Let's move to the other way.  The .concat( ); function have some similarities to "+" operator (NOTE: .concat() is not the same as "+"), aside from a fact that "+" can concat any variables compare to .concat( ) function who can concat only a string.  For example, (Explanations is on the comments!)




Tuesday, November 23, 2010

Introductory Topics before you start writing Java Codes

2
Different Data Types (most commonly use)

This short topic can give you an idea for different data types that is available to use on either the Java and C++.

a.) double num1 . . .  ;
     use to specify that the variable is a decimal point number. ex. 5.68 
b.) int num1 . . . ;
     use to specify that the variable is an integer. ex 7840 
c.) float num1 . . . ;
     same as double except that this type can handle bigger bits of decimal numbers. ex. 0.903994
d.) String word;
     use to specify that the word is a Character or a String.

Arithmetic Operators
Addition, Subtraction, Multiplication and Division.

Logical Operators

a.) Logical AND (&&)
shows that the two conditions must be satisfied in order to do a command.
Example:


The Console will ask for to enter grade then it will compute for the Grade. Later, It will decide whether the average is less than or equal to 100 and average is greater than or equal to 97.  If it is so, it will display the message "Your Great" otherwise "Better Luck next tym".




b.) Logical OR
shows that either one of the specified conditions must be meet in order to do a command.
Example:
if(x<90 || y=110){
. . . . . . . . . . . . . . . .. . . . ;
}
c.) Logical NOT
shows that if the conditional is not equal to a certain value a command will be executed.
Example:


Ternary Operators
-It uses the symbol (?).  It is a conditional that test if Exp1 is True, then Exp2 will be the value of the given expression.  If Exp1 is False, then Exp3 will be the value of the expression.
General Equation:
Exp1  ?  Exp2 : Exp3
Example

Then it will Output this one.





Incrementation and Decrementation
-It uses the symbol (++/--).  It is an operator that will add a certain value (usually 1).  It is the same as saying x = x +1.  Meaning the previous value of x will be added by 1 everytime it reach a certain condition.  So you must set a condition that will end up the adding process of the variable.
Example


In the created program, the console will keep the displaying the word "Enter grade:" until the counter reach the value of 3 (note that I initialize the value of the counter by 1).  The Program stated that WHILE the counter is less than or equal to 3 (meaning from 1 to 3), the program will keep on displaying the command "Enter Grade".  The Scanner will save the value you entered and do some operations. Finally, the program will display the output. The Console will display this one.



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.

Getting Started with Eclipse Helios

0
FAQ: How to create a new Java File in Eclipse Helios?
 Step1: Click on a "New" toolbar, choose "Project" or Go to File(Alt+F), Hover on "New" and Click "Project".










Then a Dialog Box will pop up and expand the Java folder and choose either create a "Java Project" or "Java Project on existing Ant File" and click Next and Enter the File name (it should not contain the character "/") and then click Finish.


Step2: Create a new Java Package. click on the icon at the toolbar or Go to New then Project then click Package.

The Dialog Box will pop up, click on the Browse button and choose the name of your folder who recently created.  The name of your source folder is the same to the name of your Java File. Expand the folder the click the scr folder then you must enter the name of your package (the name of your package should start at a lowercase character)  then click Finish.



Step3: Create your Main Class. Click the icon in the toolbar or Click on the File, Hover on the New then click Class.









The Dialog Box will pop-up, be sure you browse the correct path of the project source folder and the project package folder and then enter the Java Class Name (usually it is started in uppercase character), check the "public static void main(String[] args" if you like to set the class as your main class otherwise uncheck it. Then Click Finish. There you have it. Now you have your Java Class :).

Java Episode 2 - Eclipse and NetBeans IDE

0

Different Java Compliers

0
Nowadays, students and professionals are using different compilers/IDE for their Java Application.  And now we are about to compare different Java IDE's available in the market.  Some of the PUP Students, especially who is taking BSECE or BSCE, prefer to use the JEditor as their Java Compiler. But as far as I know, there are only three dominant names behind Java IDE.  These are the NetBeans, Eclipse, and JCreator.  Maybe some of the universities are using other IDE but I think the majority of the universities (even on companies) here in the Philippines are using the IDEs I mentioned.  Most of my classmate is not familiar with any of those IDEs, So Let me explain each of those for better understanding. I will not be focusing on HOW THAT IDE EXIST IN OUR WORLD state otherwise the topic will be focusing on how each components/tools are functioning. Also, the topic will be focusing on the comparison of the said IDEs.  So, lets get started. Here is a chart that can help you figure out the difference between their platforms and RCP (http://platform.netbeans.org/articles/diff-nb-eclipse.html).  Of course, the comparison is more favor to the NetBeans because this article is directly came from there website.


Comparison Chart


NetBeans PlatformEclipse RCP
UI ToolkitStandard Swing toolkitSWT
UI DesignFree, award winning, Matisse GUI BuilderCommercial alternatives
Module SystemStandard OSGi module system or NetBeans-specific module systemStandard OSGi module system
Build SystemOut of the box, Maven or AntProprietary
JDK SupportVisualVM, a NetBeans Platform application,
is in the JDK, so many JARs from the
NetBeans Platform are in the JDK too
No equivalent support
TrainingFree community-based trainings for non-commercial organizationsNo equivalent support
                                                
 

Maybe some of the beginners really don't know what the table means but as you move on to Java Programming you will be gain more knowledge about those. If we try to compare the look of those IDEs, Eclipse is better looking than Netbeans and JEditor, perhaps that makes the difference.  If we compare its stability to a Beginner Java Students they will always say that Eclipse is better than both of the IDEs said.  According to my own opinion, Netbeans is more error prone maybe it is more easy to use compare to Eclipse but still Eclipse is more stable than Netbeans or JEditor.  Maybe the JEditor also has the good interface but still Eclipse is the best. JEditor is more of the UPDATED VERSION OF NETBEANS INTERFACE state.  It is different from Eclipse. 
 
 But still the choice is yours, you can decide what is the IDE that is working for you.  There are some instances that Eclipse is better than Netbeans and JEditor is better than Netbeans.  Like for example, most of the web designer choose the Netbeans as their Editor (but there are some who use Eclipse).  They believe that NetBeans contains different plug-ins or tools which they really needed.  Another example, is most of the older professionals (whose service spans a decade or more) are preferred to use the NetBeans as their compiler for their Java Applications.  Others said that Eclipse is more Beginner Oriented (when it comes in writing codes) than JEditor or Netbeans.  I will be a good idea if i give some links for those three compilers.  It will redirect you to publisher's website there you can have another comparison and a list of good features about their IDEs. 
Watch the video in my recent post.  I hope that can help you figure out the difference between Eclipse and Netbeans.  Note: All of the software to be download is free of charge.
 
Please Leave a comment especially for PUP Students. Thanks!
Click this link to to download JDK ver. 6 (latest version)
To download NetBeans (choose your download) 
To download Eclipse (choose your download)