本文介绍了为什么Java中的字符串变量声明要大写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,当一个人声明一个字符串变量时, String一词大写,但我遇到过的其他任何类型(例如 int或 double)都没有。为什么是这样?设计师是否只是一些奇怪的任意决定?

In Java, when one declares a string variable the word "String" is capitalized, yet it isn't in any of the other types I've run across (e.g. "int" or "double"). Why is this? Was it just some weird arbitrary decision by the designers?

推荐答案

为什么在Java中将字符串变量声明为大写?

String 类型是大写的,因为它是 class ,例如 Object ,而不是像 boolean int (您可能遇到过的其他类型)。

The String type is capitalized because it is a class, like Object, not a primitive type like boolean or int (the other types you probably ran across).

作为一个类, String 紧随。简而言之,这种编码风格要求 UpperCamelCase 用于类(类名应为名词,对于每个内部单词首字母大写的情况,应混合使用)和 lowerCamelCase 用于实例和方法。

As a class, the String follows the Naming Convention for Java proposed by Sun. In short, that coding style dictates that UpperCamelCase be used for classes ("Class names should be nouns, in mixed case with the first letter of each internal word capitalized") and lowerCamelCase be used for instances and methods.

String 和基本类型?

What's the basic difference between String and the primitive types?

作为对象, String 有一些优点,例如可以直接调用它们的属性和方法(例如著名的 length() replace() split())。没有一个原始类型。

As an object, a String has some advantages, like properties and methods that can be called directly to them (like the famous length(), replace() and split()). None of the primitive types have that.

包装类怎么样?

其他基本类型具有等效的 wrapper 类,例如 Integer for int Boolean 表示 boolean 。它们将为您提供其他功能。

The other primitive types have equivalent wrapper classes, like Integer for int and Boolean for boolean. They will allow you additional functions.

自Java 1.5起,从 int 转换为 Integer 几乎无缝地设置为 。这称为。

Since Java 1.5, the conversion from an int to an Integer is made almost seamlessly. This is called autoboxing.

这篇关于为什么Java中的字符串变量声明要大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:42