您的位置:首页 > 编程语言 > Java开发

Java学习笔记 - 02

2014-03-24 22:30 281 查看
今天学习了Java的method.

在Pascal中,有返回值的“method”称为function,没有返回值的称为procedure。

C++中,统称为“函数”,Java中则称之为method。

对于有返回值的函数进行定义的时候,一定要有返回值,编译器会基础判断函数“可能没有返回值”的情况而报错。

e.g.

public static int sign(int n){
if (n > 0) return 1;
else if (n == 0) return 0;
else if (n < 0) return -1;
}
应当改为

public static int sign(int n){
if (n > 0) return 1;
else if (n == 0) return 0;
else return -1;
}


以下内容摘自<Introduction to Java Programming>.

Naming Conventions

Make sure that you choose descriptive names with straightforward meanings for the variables, constants, classes, and methods in your program. Names are case-sensitive. Listed below are the conventions for naming variables, methods, and classes.

* Use lowercase for variables and methods. If a name consists of several words, concatenate them into one, making the first word lowercase and capitalizing the first letter of each subsequent word.

* Capitalize the first letter of each word in a class name.

* Capitalize every letter in a constant, and use underscores between words.

* Choosing a unique name is important because your package may be used on the Internet by other programs. Java designers recommend that you use your Internet domain name in reverse order as a package prefix.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java