Java学习笔记 - 02
2014-03-24 22:30
281 查看
今天学习了Java的method.
在Pascal中,有返回值的“method”称为function,没有返回值的称为procedure。
C++中,统称为“函数”,Java中则称之为method。
对于有返回值的函数进行定义的时候,一定要有返回值,编译器会基础判断函数“可能没有返回值”的情况而报错。
e.g.
以下内容摘自<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.
在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学习笔记.02——泛型限定符
- Java学习笔记_02
- JAVA高级视频02_IO输入与输出 06 ByteArrayInputStram和ByteArrayOutputStream 学习笔记
- 【学习笔记02】java面向对象-成员变量、匿名对象
- 【学习笔记】java面向对象复习02
- Java学习笔记 02
- 02-Java学习笔记【并发和并行】
- [知了堂学习笔记] java基础回顾_02
- Java分布式应用学习笔记02再谈JVM
- java学习之旅(学习笔记)02
- 【JAVA学习笔记】02 运算符、表达式
- 02-java学习笔记02
- 黑马程序员 JAVA学习笔记——java基础02
- Java学习笔记_02
- Java 学习笔记02:Spring 3.0的安装
- Java学习笔记02
- 黑马程序员——学习笔记02.java的语言基础
- 【JAVA学习笔记】02 运算符、表达式
- Java学习笔记 02 Java Arrays 类的各种用法
- 【Java学习笔记】02.标识符、常量和数据类型