-1

Just wondered why some variables stated from capital letter in Java.

int num; String result;

V. Twist
  • 7
  • 2
  • 2
    `String` is object which is class and `int` is primitive this might not be main reason but in java coding standards class should start with uppercase letter – Ryuzaki L May 12 '19 at 00:51
  • 1
    You can find that out in the Java docs. Name of a class, which is case-sensitive, primitive types are lowercase. – Paul T. May 12 '19 at 00:51
  • 3
    Because, by convention all class names in Java start with a capital letter, and `String` is a class. (The full name is `java.lang.String` ...) I think it is time for you to start reading a Java Tutorial or textbook ... methodically ... because this is extremely basic stuff, and any tutorial / textbook will cover basic stuff like this.) – Stephen C May 12 '19 at 00:55
  • 1
    [Oracle Java Code Conventions](https://stackoverflow.com/questions/22961733/oracle-java-code-conventions) – Erwin Bolwidt May 12 '19 at 00:58
  • 2
    Oh yes, and `String` is NOT a variable in the context of your example. The variables are `num` and `result`. (Again ... tutorial / textbook : read!) – Stephen C May 12 '19 at 01:00

1 Answers1

1

Based on this archived article of Java's API, String is a Class and, because of the Naming conventions, it Starts with Capital Letter.

In the other hand, int, is considered a primitive type and, because of that same link, it starts with lower letters.

Similar behavior can be seen in long and Long type and Class, respectively, or float and Float.

Fingolricks
  • 1,196
  • 2
  • 14
  • 30
  • And the variables in the example are `num` and `result`, NOT `int` and `String` (those are the types of these variables). The naming convention for variables is to camelCase them starting with lowercase. – Thilo May 12 '19 at 01:52
  • I do agree with you, @Thilo. I was referring to the title of the question, that said: "Why String variable started with capital 'S' in Java?", and correct me if I'm wrong but, looks like he was asking was more related to "why int" starts with lowercase and not just like "String" which uses a capital letter "S". Either way, the question itself looks like its been resolved other times in the page as well. Thank for the feedback friend. – Fingolricks May 12 '19 at 23:36