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