Chapter 1. Fundamental Programming Structures
八个基本概念:
所有的Java方法都生命在类里,调用非静态的方法是基于该方法所在类的实例化的对象;
静态方法的调用不基于对象,程序伴随着static main方法运行;
Java有八种基本类型,五种整型,两种浮点型以及布尔型;
Java操作和控制结构与C或JavaScript非常相似;
Math类提供了常见的数学函数;
String 对象是一串字符序列,或者更精确地说, 是UTF-16编码的值;
A
String
represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in theCharacter
class for more information). Index values refer tochar
code units, so a supplementary character uses two positions in aString
.可以用System.out对象在终端输出,Scanner可以从System.in里读取终端输入;
数组和集合可以用在相同类型的元素之间;
System.out 中的out是一个PrintStream对象
public final static PrintStream out = null;
方法中定义的变量在使用前需要初始化,类中的非final变量会被设置为初始值。
public class Test {
final static int num0; //Error:(7, 21) java: variable num0 not initialized in the default constructor
static int num1;
int num2;
private void test() {
System.out.println(num2); // 0
}
public static void main(String[] args) {
System.out.println(num1);
int num3;
System.out.println(num3);//Error:(17, 28) java: variable num3 might not have been initialized
Test t = new Test();
t.test(); // 0
}
}
关于Java等编程语言选择UTF-16编码,知乎上有段野史:
www.zhihu.com/question/35214880
Java 1.8多了个排序方法
* @param a the array to be sorted
*
* @since 1.8
*/
public static void parallelSort(byte[] a){/** **/}
来源:oschina
链接:https://my.oschina.net/u/921876/blog/660817