Java learning notes (1):Basic Knowlege points

Basic Knowlege points:

1: it's necessary that there is only one public class in per .java file

2: .java file name should better to same as class name

3: when set the environment variable CLASSPATH, you should make sure the '.' path can't be lack of.

4: java is case sensitive, including .java file name , class name, variable name, method name and so on.

5: JVM uses automatic garbage collection machanism. It just collects memory source, not contains physical source, such as database connection, disk IO. You can invoke a collection through call static method System.gc().

6:Java is strong-type language, the variable shouble be declared firstly and then you can use it. ② the vairable only can accept the value which type is consistent with itself.

7: /**   */  is used to add document annotation for java. javadoc command can export the code API document.

8: use '...' follow method parameter type, means has at least one parameter or more parameter. It equals type array type[]. it's similar with params in C#

9. In java, lamda expression use '->' symbol

10. From java 7, switch statement was allow to use String type, before just includes byte, int, char, shot four type.

11.For java, object instance can access the class static method or static field. but in c#, That's illegal.

12. For java, the package is similar with namespace in c#

13. for classes they belongs to same packege, don't have to at the same directory. That means there can be several packages with same name, but these packages should at different directory. And .class file should at the directory which name is same with its package name.

14. in java, 'instanceof' keyword equals 'is' in C#; there isn't  keyword like as 'as'.

15. In Java, support initialization block , don't in c#.

public class A

{

 { ... block }

}

note: the execute order is that: create class object, initialize block, initialize field, constructor

if all class object have same logic, or initialize code, we can use static initialization block

16. In java, final keyword is same as sealed in c#.

17. the relationship of basic type with their packaged class

 

when convert between basic type with packaged class, system will boxing or unboxing automatically.

 

 18. for value type and reference type which are defined by 'final' keyword', difference is following:

1. final value type can't be changed or modified anymore.

2. final reference type' reference which is pointer address is can't changed, but the object fields can be modified or changed.

Note: it's same as 'readonly' key word and 'const' key word in c#.

19. Object reference:

1. StrongReference ---- when system collect garbage, the object will not be recycled.

2. WeakReference ---- when system collect garbage, the object will be recycled compulsively.

3. PhatomReference  -----  the object will be recycled compulsively. it can't get object address reference use PhatomReference. it just to use to trace the object.

4.SoftReference   ------ when system collect garbage,  if the memory is not enough , the object will be recycled compulsively.

Note: it's alse same as WeakReference in c#

 

转载于:https://www.cnblogs.com/anthonyBlog/p/3981863.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值