Results 1 to 5 of 5
Thread: int, float, double BUT String
- 04-25-2011, 05:28 AM #1
Member
- Join Date
- Apr 2011
- Location
- Sydney, Australia
- Posts
- 5
- Rep Power
- 0
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
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 exampleJava Code:int temp = 0; float temp1 = 0.0; double temp3 = 0.0;
any one can explain this please ?Java Code:String name = "myName";
Regards
-hisheeraz
- 04-25-2011, 05:36 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 04-25-2011, 05:41 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 04-25-2011, 05:45 AM #4
Member
- Join Date
- Apr 2011
- Location
- Sydney, Australia
- Posts
- 5
- Rep Power
- 0
Got the Idea fellows, many thanks
and regards
-hisheeraz
- 04-25-2011, 05:47 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
What is the difference between float and double?
By Nosrettap in forum New To JavaReplies: 3Last Post: 01-31-2011, 02:45 AM -
double and float value in java
By arvindmer in forum New To JavaReplies: 6Last Post: 05-28-2009, 04:51 PM -
Float vs. Double
By javanub in forum New To JavaReplies: 1Last Post: 11-23-2008, 12:11 PM -
Float and double to binary
By rosh72851 in forum Advanced JavaReplies: 3Last Post: 09-24-2008, 06:29 AM -
Put float value to double
By chamalsl in forum New To JavaReplies: 3Last Post: 09-20-2008, 04:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks