[Java] Variables and Types

Iamcoolz Jul 31, 2014

  1. Iamcoolz

    Iamcoolz Forum Administrator Staff Member XPG Administrator

    Mar 30, 2012
    Likes Received:
    Trophy Points:
    Xbox One
    What is up XPG

    Another programming tutorial and this time we will dive into what begallegal1 is studying. Java is one hell of a program, and in my adventures in College, I took a small class regarding it and enjoyed myself. However, Java was one of the programming languages I grasped rather quickly compared to most! In this tutorial we will go over the different variables and their types. This is a simple tutorial and will basically explain the differences between the two, and their role in Java.

    Variable: it is basically a placeholder or a identifier which would have some known or unknown information. Most of the time, it is a value.

    Type: A type is just a set of various types of data.

    We will firstly begin with the more built in basic data types.

    byte: (number)
    short: (number)
    double: (floating number) - i.e. 5.1, anything with a decimal involved is a floating number.
    long: (number)
    int: (number)
    char: (a character) - This is mostly defined as text.
    boolean: (True or False)


    To set and put a number to a data type:

    int Number;
    Number = 5;
    or to be even more efficient:

    int Number = 5;
    This rule applies to most of them, and its that easy to set them.

    float f = 4.5;
    Float allows you to add a decimal to the number!

    Strings and Characters:

    For the character and well text settings:

    char Name = 'Iamcoolz';
    Strings and how to combine them:

    String String1 = new String(" Hello XPG and welcome to a tutorial by:");

    String String2 = new String = ("Iamcoolz");

    String String3 = String1 + String2;
    Now looking at the above, we went over how to add numbers so let's add it a string, to make a combined sentence using a variable set by you!

    int MyNumberz = 365;
    String String1 = "There are " + MyNumberz + " days in a year";
    Now Boolean is a bit more complicated, however, still rather simple.

    if (temperature > 75 ) {
    system.out.println("It is somewhat nice outside");
    Using an IF statement, you can make booleans come to life!

    I hope this wasn't too tough to read, I am a tad bit tired so


Share This Page