Java Basic (J2SE) tips keep updating

本文深入探讨了Java中的多个关键概念,包括多重继承的限制、封装、同步块与方法的区别、接口的作用、静态变量的声明限制、可见性元素在UML中的表示、对象实例化、表达式的计算规则等。同时,还提供了具体的代码示例来帮助理解。

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. 转自优快云论坛

一个抽象类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'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值