Results 1 to 5 of 5
  1. #1
    hisheeraz is offline Member
    Join Date
    Apr 2011
    Location
    Sydney, Australia
    Posts
    5
    Rep Power
    0

    Question int, float, double BUT String

    Hello once again;
    I have this little question.

    In Java, Data types are reserved words and they appear
    in specific colour (using eclipse) and are all in lower case
    for example
    Java Code:
        int temp = 0;
        float temp1 = 0.0;
        double temp3 = 0.0;
    but why is it the case with string declaration that is appears black in colour and String keyword itself has to be declared with first letter capitol for example
    Java Code:
        String name = "myName";
    any one can explain this please ?

    Regards
    -hisheeraz

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Data types are not reserved word. Primitive data types are. That is a key distinction.

    String is just a class, the reason why you associate it with the other primitives is because it is so important in computer programming. If you are familiar with c, they use character arrays to represent a string. In actuality(in java) a string is a character container. It handles all string operations for you.

    Just as a JFrame is a class defined in the java class library, so is string. If you need more explanation, please let me know.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    int, float and double are primitive types but String is a reference type (it is associated with the class java.lang.String while the other three do not have classes). The convention with Java is that reference types start with a capital letter: you are free not to this but the classes that come with the JDK all start with a capital letter.

    CaSe MaTtErs. So if you mean the class java.lang.String you must say "String" and not "string".

    Typically you create new instances of a class by using the "new" keyword. Strings are a little different in that you can create them with a so-called string literal. (a string literal is just letters inside quotes as in the example you posted).

    That Eclipse uses a special colour for the keywords associated with the primitive types is just what it does. Presumeably to make them stand out. You can customise its behaviour at Window->Preferences->Java->Editor->Syntax coloring.

  4. #4
    hisheeraz is offline Member
    Join Date
    Apr 2011
    Location
    Sydney, Australia
    Posts
    5
    Rep Power
    0

    Default

    Got the Idea fellows, many thanks
    and regards
    -hisheeraz

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are welcome. Please mark your thread solved if you do not have any more questions. You can do this with the thread tools near the top right of the page.

Similar Threads

  1. What is the difference between float and double?
    By Nosrettap in forum New To Java
    Replies: 6
    Last Post: Today, 12:20 PM
  2. double and float value in java
    By arvindmer in forum New To Java
    Replies: 6
    Last Post: 05-28-2009, 04:51 PM
  3. Float vs. Double
    By javanub in forum New To Java
    Replies: 1
    Last Post: 11-23-2008, 12:11 PM
  4. Float and double to binary
    By rosh72851 in forum Advanced Java
    Replies: 3
    Last Post: 09-24-2008, 06:29 AM
  5. Put float value to double
    By chamalsl in forum New To Java
    Replies: 3
    Last Post: 09-20-2008, 04:52 AM

Posting Permissions

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