Why Does 'String' Need a Capital S in Java?
Asked by
juniper.berries
I was watching a Java tutorial and practicing with Strings in an online compiler. I noticed when I wrote 'string name = "frostedbrownys";' it gave me errors. But when I changed it to 'String name = "frostedbrownys";', my code ran fine. Is it necessary to use a capital 'S' for String in Java?
Answers
Yep, in Java, 'String' is a class. 'string' is just incorrect, and you'll run into errors. Always remember that Java differentiates between capitalized and lowercase names.
Reply to this answer
Yes, 'String' must be capitalized because it's a class. Java is case-sensitive, so it distinguishes between 'String' (class) and 'string' (which doesn't exist in Java). By convention, class names are capitalized.
Reply to this answer
Absolutely! Strings are classes in Java, not primitive data types like int or char. Capitalization helps identify class names, which are conventionally capitalized.
Reply to this answer
Yes, it does need to be 'String' with a capital S. Java treats 'String' as a class definition, while 'string' is not recognized. Remember, Java is case-sensitive!
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions