The moose likes Beginning Java and the fly likes String int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String int" Watch "String int" New topic

String int

patrick van merchtn

Joined: Apr 04, 2007
Posts: 9
very small question.

In my HF book on page 79. Is there a convention to name primitives variables starting with a capital or not. Or does it make no sense ?

//type String starts with a capital.
// type int all lowercase.
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

The convention is for class names to start with a capital letter, primitive types do not. In your example, "String" is the simple class name for "java.lang.String" whereas "int" is a primitive type (i.e. not a class name). If you were to use the "java.lang.Integer" class, which is different from the primitive type "int" then you would (have to) capitalize the first char.
In some sense autoboxing in Java 1.5 has made this more confusing because it looks more like "java.lang.Integer" and "int" are synonomous when they are definately not.
Variable naming convention is a different subject. See the java coding conventions at
I agree. Here's the link:
subject: String int
It's not a secret anymore!