Reputation: 31
I am a newbie to Java and just starting to learn the language but I am hitting a few snags along the way and I was hoping you can give me some direction on an issue I am having.
I know Java is case sensitive when it comes to things like variables and some reserved words. However I cannot wrap my head around which ones to use lower case and which ones to use upper case. For example I know you have to use lower case on class. But for System you have to use capital S or it will error during the compile phase.
Can someone give me some help understanding when to use upper and when to use lower case for java commands? Is everything lowercase unless I reference another object and then does it depend if that object is saved with and uppercase or lowercase name?
Upvotes: 3
Views: 6184
Reputation: 125
the following is useful,simple variables = starting with lowercase,Class Name = starting with uppercase,Final variable = all capital ,methods = starting with small letter
Upvotes: 0
Reputation: 47183
The most accurate answer is "use the same case as the name you are using". So, if the class is called System
, you have to write System
. If the method is called print
, you have to write print
.
I realise that this is not immediately helpful, but it is the truth, and it is something you will need to learn to cope with.
Other answers are giving you very helpful general rules about the casing of types (classes are UpperCamelCase, methods are lowerCamelCase, constants are UPPER_WORM_CASE), but the thing is, there are exceptions. Not many in the JDK code, but in libraries you pull in and codebases you inherit, there will be exceptions. In a codebase i work on, there are numerous enum constants whose names are UpperCamelCase instead of the proper ALL_CAPS_WORM_CASE, and our convention is for test methods, and many testing utility methods, to be named in lower_worm_case.
So, the really important thing to learn and internalise is that the name you write must match the name as defined. That is the only true rule that applies.
Upvotes: 1
Reputation: 119
Try using this:http://en.wikiversity.org/wiki/Learning_Java
It will help you learn Java and has can help you to navigate any issues you may have at the beginning.
Upvotes: 0
Reputation: 68715
You need to read, understand and use the Oracle java coding guidelines, here you go:
http://www.oracle.com/technetwork/java/codeconv-138413.html
Naming section:
http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367
Upvotes: 4