+ Reply to Thread
Results 1 to 7 of 7

Thread: Java:Tutorial - Data Types

  1. #1
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,883
    Blog Entries
    25

    Java:Tutorial - Data Types

    This is not exactley a tutorial, but rather information you should know before you start using Java. I will be refering to in in future tutorials.

    Unlike my favorite web-based programming language, PHP, Java requires you to declare your variable to a type.

    int x = 0;
    String y = “Hello World”;

    Below are a list of all the data types in Java and a brief explanation of each.

    char: Has the ability to hold a single letter. I’ve never once used this data type.
    String: The data type string can hold any string including numbers, letters, and special characters. However you must note that the number 5 stored as a string is NOT evaluated as a number. Also for the longest time I always wondered why String was the only data type with a capital letter. I recently found out that String is a reference to a class. Its default value is evaluated to be “null.”

    byte: This data type can hold any numeric integer from -128 to 127. Its default value is evaluated to be “0.”
    short: This data type can hold any numeric integer from -32,768 to 32,767. Its default value is evaluated to be “0.”
    int: The data type int can hold any numeric integer from -2,147,483,648 to maximum value of 2,147,483,647. Its default value is evaluated to be “0.”
    long: The long data type can hold any numeric integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Its default value is evaluated to be “0L.”


    float: The float data type is used for decimals. I believe it is 32 bytes and has the ability to hold 754 floating points. Its default value is “0.0f”
    double: The double data type is also used for decimals. It has more precision than float and is often referred to as double-precision, hence the name. It is 64 bytes and also holds 754 floating points. Its default value is “0.0d”.

    boolean: This data type can either store true or false. It is very useful for state functions and is often used in loops. Its default value is “false”.


    For the most part, this information applys to other programing languages, but for our porposes, these are the specific data types in Java.

  2. #2
    Newbie castanza88 is an unknown quantity at this point
    Join Date
    Dec 2006
    Posts
    5

    which one to pick

    If not using large amounts of data, is it ok to not have to get an exact data type for your variable for basic needs?

  3. #3
    Newbie castanza88 is an unknown quantity at this point
    Join Date
    Dec 2006
    Posts
    5

    followup

    I would usually pick an "int" for a basic data type for any number that I use...

  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,883
    Blog Entries
    25
    Quote Originally Posted by castanza88 View Post
    If not using large amounts of data, is it ok to not have to get an exact data type for your variable for basic needs?
    for most programs it really dosnt matter, it would guess for large applications it would be more wise to use the "best" data types for the job. that way you dont allocate too much memory thats not being used. However with that said, ive only ever used boolean, String, int, and double

  5. #5
    Newbie rong889 is an unknown quantity at this point
    Join Date
    Jun 2007
    Posts
    2
    Quote Originally Posted by castanza88 View Post
    I would usually pick an "int" for a basic data type for any number that I use...
    Sometimes you need to use the accurate type.

  6. #6
    Newbie brian is an unknown quantity at this point
    Join Date
    Jun 2007
    Posts
    13
    Nice description of the datatypes.

    One thing though is that these are just primitive data types and not objects. The nice thing about java is that it is object oriented, and so you create objects (which are like a more complex data type) and so you have virtually unlimited number of datatypes in reality....because you create them.

  7. #7
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,883
    Blog Entries
    25
    Quote Originally Posted by brian View Post
    Nice description of the datatypes.

    One thing though is that these are just primitive data types and not objects. The nice thing about java is that it is object oriented, and so you create objects (which are like a more complex data type) and so you have virtually unlimited number of datatypes in reality....because you create them.
    Not all of them are actually primitive data types. In Java Strings are objects, more specifically, an Abstract Data Type [ADT] -- essentially an array of characters.

    But yes, in OOP, there are unlimited ADT's.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Fetching Data from a Form Generated Website
    By pclark2 in forum General Programming
    Replies: 5
    Last Post: 05-11-2007, 06:24 AM
  2. Please help me , Post Data & Store Data
    By minusp in forum PHP Forum
    Replies: 7
    Last Post: 03-23-2007, 07:00 PM
  3. Abstract data types in C++
    By priorityone in forum C and C++
    Replies: 1
    Last Post: 01-08-2007, 11:43 AM
  4. What Is A Union
    By ravs2k6 in forum C and C++
    Replies: 2
    Last Post: 07-08-2006, 01:14 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts