Java Basic (J2SE) tips keep updating

1. Unlike languages such as C++, Java DOES NOT allow multiple inheritance.

We can do sth like this

public class Child extends Mother, Father{}

2. Tight encapsulation.

Outside visit is not allowed.

3. Synchronized blocks place locks for shorter periods than synchronized methods.

4. Iterface allows an implementation of a class

5. Static variable cannot be declared as local (only as member).

6. Visibility element in UML

"+" public "-" private "#" protected "~" package

7. Create a object,this object is a INSTANCE of the class.

8. Class is a named collection of fields, hold date values and methods that operate on those values.

9. i=1;i+=i+++++i; 结果i输出5.

10.Cannot make a static reference to the non-static field.

11. Date range of short type -32768 - 32767,char's 0-65535

12.while loop will not accept false value directly in it. Value should be true or boolean expression (dynamic) is required to evaluate.

13.

for (int i = 0; i <= 3; System.out.print("a" + i))
System.out.print("b" + i++); System.out.print(xxx) in for condition will be executed after System.out.print(xxx) in for loop.

14. URL in code:

"Http: // www.google.com;", In code segment,Http: will be considered as Label,// www.google.com will be considered as comment.



15. (label)Continue cannot be used outside of a loop

16. for (int i=0, int v2=0; i<1; i++,v2++) int i=0, int v2=0 is wrong,it should be "int i=0,v2=0".

17."while (i < 5) i++; j--; " equals "while(i<5){ i++;} j--;

18. %取余;负数在取余的后面结果是正的;负数在取余的前面结果是负的

19. The bitcode produced is more efficient. Is b=a<<1 faster than b=a*2

20. Floating point numbers don't produce an Arithmetic exception.

21. byte c; c+=5; implicit cast .

22. Static variable,execute at the earliest

23. About Final.. a). final class can't be subclass b).final method can't be overridden c).final variable can't be reinitialized

24. Static constant are initialed in sequential order.

25. 转自CSDN论坛

一个抽象类Test1:
public abstract class test1 {
int i=0;
}

一个接口Test2:
public interface test2 {
int i=2;
}

问题:请在下面横线处填写代码分别输出test1和test2中变量i的值
public class test3 extends test1 implements test2 {


public void print()
{
System.out.println(super.i); //abstract 是继承,所以可以用super.i interface 是实现。

System.out.println(test2.i);//
在interface中,所有的成员变量都是默认public final static , 静态的所以test2.i。


}
public static void main(String[] args) {
test3 t=new test3();
t.print();
}

}

插一条firebug eclipse使用说明 : step over 执行到方法,跳过方法内部细节继续执行 step into 相反,进入细节执行。step out 跳到上层调用执行。

26.multiple extends

publicinterfaceMyInterfaceextendsInterfaceA,InterfaceB

What does the following code print:

System.out.println(MyInterface.class.getSuperclass());

the result will always be 'null'

你可能感兴趣的:(java,J2SE,Google,Firebug,UML)