+ Reply to Thread
Results 1 to 7 of 7

Thread: Java:Tutorial - Data Types

  1. #1
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    castanza88 is offline Newbie
    Join Date
    Dec 2006
    Posts
    5
    Rep Power
    0

    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?

  4. #3
    castanza88 is offline Newbie
    Join Date
    Dec 2006
    Posts
    5
    Rep Power
    0

    followup

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

  5. #4
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    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

  6. #5
    rong889 is offline Newbie
    Join Date
    Jun 2007
    Posts
    2
    Rep Power
    0
    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.

  7. #6
    brian is offline Newbie
    Join Date
    Jun 2007
    Posts
    14
    Rep Power
    0
    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.

  8. #7
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    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. Abstract data types
    By toto_7 in forum General Programming
    Replies: 17
    Last Post: 04-28-2011, 02:42 AM
  2. Generic data types in C
    By DarkLordofthePenguins in forum C and C++
    Replies: 6
    Last Post: 03-02-2011, 07:16 PM
  3. Data types of PL/SQL and SQL
    By Patrick in forum Database & Database Programming
    Replies: 0
    Last Post: 10-07-2007, 12:52 AM
  4. Abstract data types in C++
    By priorityone in forum C and C++
    Replies: 1
    Last Post: 01-08-2007, 09:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

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