Tutorial Categories
Tools and Software
Site Search


Advanced Search
Tutorial Options
Popular Tutorials
  1. Photoshop Concept Car Makeover
  2. Photoshop Man Of Fire Part I
  3. Photoshop Magic Marker Effect
  4. Photoshop Man Of Fire Part II
  5. Photoshop Car Makeover Part II
No popular tutorials found.
Popular Authors
  1. Cory Crampton
  2. Daniel Phillips
  3. tanmay goswami
  4. Rails Forum
  5. Brendan Horverson
  6. CodeCrunch Tutorial Bot
  7. PhotoshopBee .com
  8. Jamie Lewis
  9. Nick Cote
  10. Luther Avery
No popular authors found.
 »  CodeCrunch  »  Programming  »  Java Tutorials  »  Java Basics Part 1
Java Basics Part 1
By Lee Labit | Published  06/30/2006 | Java Tutorials | This tutorial viewed 891 times
Java Basics Part 1
Suppose that you want to calculate something. First you must set up variables. Variables are things that stores values. For storing strictly numbers, use int (for whole numbers) or double (for numbers that have a dot like 5.12345). For words or a combination of words or numbers, use String:

The way you declare variables is this:

public class MyClass
{
    public static void main(String[] args)
    {
        int a = 10;
        int b = 25;
        String name = "Yahoo12345";
    }

}
Note: You must use semi colon after each statement of your code and you must put double quotes for the value of a String variable. To do a quick arithmetic on our two ints, set up a new variable like int answer = 0; Note: If you are setting up a placeholder like the "answer" int variable, set up the initial value of it to zero.
Now type "answer = a + b;" and "System.out.println("My answer is " + answer);". Your code should now look like this:

public class MyClass
{
    public static void main(String[] args)
    {
        int a = 10;
        int b = 25;
        String name = "Yahoo12345";
        int answer = 0;
        answer = a + b;
        System.out.println("My answer is " + answer);
    }

}

After you compile it and run it, you should now see a new window that displays "My answer is 35".
 


How would you rate the quality of this tutorial?
Add comment
Comments