建筑专业,毕业,无编程基础,4个有考过SCJP1.4,复习心得
(1) Two public classes in the same file. (illegal)
一个文件里两个公有类(错)
(2) Main method calling a non-static method. (illegal)
Main方法里访问非静态方法(错)
(3) Methods with the same name as the constructor(s). (这种题常有)
构造函数方法名相同
(4) Thread initiation with classes that do not have a run() method. (常考之题)
初始化一个没有run方法的线程类
(5) Local inner classes trying to access non-final vars. (illegal)
定义在方法里的内部类不能访问方法里的变量
(6) Case statements with values out of permissible range. (byte,int, short, chat)
在switch里的case里声明的值与switch里声明的值的范围不同,例如:
byte a;
switch (a)
case 1000:
(这是错的)因为a的范围是128 ~ -127
(7) Math class being an option for immutable classes !! (totally wrong!)
(8) instanceOf is not same as instanceof.
(9) InstanceOf不是instanceof
(t instanceof Person) t 是否Person类的对象 (是就返回true)
(10)Private constructors. (legal) 私有构造函数是合法的。
(11)An assignment statement which looks like a comparison. (比如说if(a=true),对于这种题眼睛亮一点) 在比较操作时时使用了一个象比较语句的赋值语句。例如(a==true,写成了a=true)
(12)System.exit() in try-catch-finally blocks.
(finally 不会执行)
System.exit()在try-finally里是不会执行的。
(13)Order of try-catch-finally blocks matters.
(若顺序错的话: error: No try before catch)
Try-catch-finally语句的顺序问题。
(14)main() can be declared final. (OK)
(15)-0.0 == 0.0 is true. -0.0==0.0是成立的。
(16)A class without abstract methods can still be declared abstract.
一个没有抽象方法的类也可以是抽象类。一个非抽象方法死活也别想override成一个抽象方法
(17)RandomAccessFile descends from Object and implements DataInput and DataOutput.
(18)Map does not implement Collection.
Map(映射)没有实现Collection(集合)接口
(19)Dictionary is a class, not an interface.
Dictionary是一个类而不是一个接口。
(20)Collection is an Interface where as Collections is a helper class. (这题我倒没见过,但还真容易看混)
Collection是一个接口,而Collections却是一个辅助类。
(21)Class declarations can come in any order.
(也就是说: class Child extends Parents{}
class Parents{}这种顺序是可以的.)
类的声明顺序可以是任意的,可以先声明子类再声明基类
(22) Forward references to variables gives compiler error.
( 一个变量未被赋值时)提前引用它是会导致编译错误的。
(23) Multi dimensional arrays can be sparce.
(这句话是说: 多维数组中子数组不一定必须有一定个数的元素,比如我们把一个二维数组看成一个矩阵,那么行与列中的元素可以不完整,可以不对齐.)
(24)Arrays, whether local or class-level, are always initialized.
数组,不论是类等级的,还是本地的,只要被new了出来,就已经被初始化了。
(25)Strings are initialized to null, not empty string.
字符串初始化时null
(26)An empty string is NOT the same as a null string.
一个空字符串并不等于null
(27)A declaration cannot be labelled.
一个声明语句不能被标记。
(28)"continue" must be in a loop(for, do, while). It cannot appear in case constructs.
Continue必须在循环里,并不能在case结构里。
(29)Primitive array types can never be assigned to each other, eventhough the primitives themselves can be assigned.
(也就是说: ArrayofLongPrimitives = ArrayofIntegerPrimitives 会编译出错,但 longvar = intvar 是合法的)
Primitive(int,char,long等)数组是不能互相赋值的,即使它们本身可以(?)
(30)A constructor can throw any exception.
构造函数可以抛出任何异常。
(31)Initilializer blocks are executed in the order of declaration.
(32)Instance initializer(s) gets executed ONLY IF the objects are constructed.
(33)All comparisons involving NaN and a non-Nan would always result false. (对大多数朋友来说这可是个盲点噢)
(34)Default type of a numeric literal with a decimal point idouble.
(我在这里把Java成员变量默认初始化原则写一下:
成员变量类型 取值
byte 0
short 0
int 0
long 0L
char '\u0000'
float 0.0F
double 0.0D
boolean false
所有引用类型 null )
(35)integer (and long ) operations / and % can throw ArithmeticException while float / and % will never, even in case of division by zero.
integer和long 操作 /和% 的话, 会抛ArithmeticException, 但是 float不会,即使是除以0
(36)== gives compiler error if the operands are cast-incompatible.
当操作数性质不同时,==运算导致编译错误。
(37)You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast.
同一基类的两个子类之间不能互相转换!子类继承父类时并不继承构造函数
(38)equals returns false if the object types are different.It does not raise a compiler error.
当对象不相等时,Equals会返回false,但不会编译错误。(但前提是括号内必须是一个非null对象,注意:是非null!)
(39)No inner class can have a static member.(but static inner class can)
除了静态内部类外,非静态内部类不可以有静态成员。
(40)File class has NO methods to deal with the contents of the file.(also the existing directory)
(41)InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.
(42)String类型不能进行“-”运算
(43)sizeof不是Java关键字而const是! Const是一个Java未被使用的关键字
(44)Object a=new float[10]; 是对的 Object[] a=new float[10];是错的。
前者是创建Object对象,此对象指向一个float[10]的实例;后者是强制把float类型转化为Object类型,所以出错。