Is this a real dumb question? Is there a real good reason for having Java code case sensetive?
I'm muddling my way through the book 'Java Head First' and sorta getting there. Slowly. Remembering the commands is hard enough but also remembering the upper/lower info is maddening and seems unnecessary.
Most are lower case such as int, while, public etc then every now and again there is a capital; String, System etc. WHY???
There has to be a good reason for it, it can't just be for aesthetics. Can it?
Most are lower case such as int, while, public etc then every now and again there is a capital; String, System etc. WHY???
if you take a closer look you'll see that those starting with capital allways refer to class names, while all the others are method names, variable names and so on.
there's a set of rules and conventions you'll gradually absorb
one example when you declare a variable being of type "String", you write: notice that i used camel notation in naming my variable so that's easier to read [ May 22, 2005: Message edited by: miguel lisboa ]
This convention also allows you to write something like
Customer customer;
To someone used to the Sun coding convention, it's immediately obvious that Customer is a class/interface, whereas customer is a variable of type Customer.
So it's illegal to start a variable or string with a capital, EVER?
No, it's just a convention -- a universally obeyed one, but just a convention. You can break the convention, but then your code is harder for seasoned Java programmers to understand.
Given that something already has a name, though, you have to use the capitalization that was used to define it. Hence, the class String always will start with a capital "S", because that's how it was defined.
"out" is a public, static member variable in the System class (more properly, the java.lang.System class.) "out" is an instance of the java.io.PrintStream class, which has a number of overloaded "println" methods.
So you're saying "call the "println" method on the "out" member of the "System" class."
You'll learn all this stuff in due time. I know it sounds crazy now but you know, that's about as complicated as it gets, and once that all makes sense, you're set.
Originally posted by Tim Dee: Is this a real dumb question? Is there a real good reason for having Java code case sensetive?
I'm muddling my way through the book 'Java Head First' and sorta getting there. Slowly. Remembering the commands is hard enough but also remembering the upper/lower info is maddening and seems unnecessary.
Most are lower case such as int, while, public etc then every now and again there is a capital; String, System etc. WHY???
There has to be a good reason for it, it can't just be for aesthetics. Can it?
To answer your original question, Java is case-sensitive because computers are inherently case-sensitive. First you should understand how the computer stores characters. A character is any symbol you can type on the keyboard (plus some other symbols that you can't, but we won't go there). The computer associates each of these symbols with a number. In the U.S., many older computers use what is called the ASCII table for this association. In more modern computers, and particularly in Java, the Unicode standard is used to determine which number is associated with each character. In this scheme, upper- and lower-case letters each have a unique number. For example, 'A' is number 65 and 'a' is number 97. Typically in programming, these exact values are unimportant as you can use character literals (such as 'A') to indicate a character.
This means that in order to make software so it ISN'T case-sensitive, the programmers have to go to extra work in order to make sure that 'a' and 'A' are the same thing. In this case, the creators of Java decided not to go to that extra effort. I would guess that one reason is because Java is very similar to C++ which is also case-sensitive.
notice that i used camel notation in naming my variable so that's easier to read
[ May 22, 2005: Message edited by: miguel lisboa ]<hr></blockquote>
By Camel notation you mean a capital at the new word yes? So the name has a hump in it I guess.
So it's illegal to start a variable or string with a capital, EVER? I guess that makes them easier to spot especialy with the 'Camel Notation' system.
Many thanks for the help.
[ May 22, 2005: Message edited by: Tim Dee ]
[ May 22, 2005: Message edited by: Tim Dee ][/QB]
You are on the right track. CamelCase (or CamelNotation) means that each new word starts with a capital letter. This is a common convention used in Java. However, as noted above, it is just a convention. The compiler will let you use wHateVer CapItAliZaTion you wish. However, following conventions makes code much easier to read.
Layne
Post by:autobot
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, the permaculture playing cards