• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on proper case for classes and variables  RSS feed

 
joseph dela cruz
Ranch Hand
Posts: 38
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Kabayan Joseph,

First of all, no offense but the coding style (seemingly random capital letters in the names) in your sample code is atrocious. Please don't do that in real code. Secondly, what you show is not at all overloading. Overloading is when you use the same method name and return type but allow different parameters to be passed. A good example of overloading: see the many different types of parameters you can pass to String.valueOf()

Edit: See discussion regarding return type below


its ok atleast im commiting my errors now as a student
i just thought that what i was doing was camel back spacing haha and by the way its not random its 3rd letter of the variable that is capital anyway if its wrong then i shall remove it in my practice and thanks for all the comments
 
joseph dela cruz
Ranch Hand
Posts: 38
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way can i ask what is the difference between

Kano Kano; vs Kano Kano = new Kano();

and

char[] a = "asdf".toCharArray();

String.ValueOf(a) vs new String(a);

and i just want to ask is new String(a) is casting char array to string or no? is it similar to this (int)a[1] casting it into an integer

thanks for all your answers please do not hesitate to tell me if i have misconception on certain things and if im doing something wrong or in a very hard way
i am open minded and i want to learn
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it was called camel-case. But that means the first letter of each word is Capitalised when the words are allRunTogether. (all run together)
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joseph,

Java identifiers are case-sensitive so 'Kano' and 'kano' are considered as two different identifiers.

See http://java.about.com/od/javasyntax/a/nameconventions.htm for a good discussion of Java naming conventions. And it's called "CamelCase", not "Camel back."

String.valueOf() (note the case convention for method names) is preferable over new String(..). No, the latter is not the same as casting. Casting simply tells the compiler to use a particular type; no memory is allocated for a new object as is the case with new String(). See http://www.coderanch.com/t/524964/java/java/When-new-String-against-string for more.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice article, but I am not sure about interfaces beginning with the letter I. That is, I think, however, the usual convention in C#. Also note how many interface names end in able or ible.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Nice article, but I am not sure about interfaces beginning with the letter I.

Ugh. Totally agree. Smacks of the old "type prefix" to me, which I never liked; even back when it was possibly worth something.

Winston
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add my vote against the "I" prefix to mark interfaces. The practice my teams uses is to give an implementation-agnostic name to the interface (go figure) then use qualifiers that help distinguish different implementations. This is most commonly used with our Repository services: CustomerDao would be the interface name, then JdbcCustomerDao or HibernateCustomerDao would be specific implementations.

Joseph, note that when using mixed or camel case, you would capitalize at the start of a word, not at some arbitrary position like "the third letter" as you were doing before. The intent is to make it easier read the code and remove ambiguity

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!