Java Fundamentals 1

Source: Internet
Author: User
Tags wrapper

  

  

1. Java variable type: member variable, local variable, static variable

Modifier public, private, protected, default can only modify member variables, cannot decorate local variables.

Private, protected cannot be used to modify classes, only public, abstract, or final can modify classes.

2, the interface in Java has no method: These interfaces are also declared as identity interfaces, indicating that the class implementing it belongs to a special type (a instanceof B).

The member modifiers of the interface are public, and the method can only be modified with public and abstract, and the constant default public static final decoration.

3, Java in the processing of the basic data type (Int,char), is to pass by value, other than the other types are passed by reference (like a pointer, modify the value of the object and the original object synchronization), = is also passed by reference.

You can use clone to replicate an object, implement the Cloneable interface first, and then override the Clone method.

4, in depth clone, you need to clone the object members in the class. (Obj.birth = This.getbirth (). Clone ())

5. Object-oriented:

Features: inheritance, polymorphism, encapsulation, (abstract)

Polymorphic 2 Mechanisms: Run-time polymorphism (implemented by subclasses overriding the parent class method) and compile-time polymorphism (by means of method overloads (same method name, number of different method parameters, type, order), member variables cannot be polymorphic.

6. Abstract classes and Interfaces:

Abstract methods of abstract classes cannot be modified with private, synchronized,static, and native. Interfaces can inherit interfaces, abstract classes can implement interfaces, and abstract classes can inherit concrete classes.

7. Inner class:

Static inner class: The static Class a--can only access statically members and static methods of external classes, including private.

member Inner class: a non-static inner class cannot have a static member.

Local inner class: In the method of the outer class, like local variables, the local inner class cannot be decorated with public,static, and can only access variables defined in the method as the final type.

Anonymous inner class. There are no constructors, no static members, methods, and classes, and it is also a local inner class

8, GetClass in object is defined as final and native, polymorphic. Subclass constructor method to invoke the constructor of the parent class, super must be on the first line of the method.

9. Identifiers:

Must consist of letters, numbers, underscores, and $, and numbers cannot begin as identifiers.

10, there is no global concept in Java, but static can achieve the same effect. You cannot define a static variable in a method

11. Switch () can only be followed by string or Int:switch () {case str: ...; break;}

12, volatile is a type modifier, used to modify the variables that are accessed and modified by different threads, variables defined by it are directly to the memory to fetch instead of caching.

13. Raw Data type: CHAR2 (Unicode character), Int4, Float4, Double8, Long8, Boolean1, Short2, byte1 initial value is 0

Reference data type: Array, class, interface. The initial value is null, and the address value is stored

14. Immutable Classes

Refers to the creation of this class, and can no longer modify its value, that is, its member variables. Member variables are private, methods are constructed only, and all methods are not overwritten. This class can be changed through clone.

15. Value passing and reference passing:

Value passing: The parameter is simply an argument value that initializes a temporary storage unit, so the formal parameter and the argument have the same value, but with different storage units, changes to the parameters do not affect the argument.

Reference passing: The address of the object is passed, so the formal parameter and the argument point to the same storage unit, and the modification of the parameter will sound to the value of the argument. However, the amplitude operation of the parameter inside the function may not affect the argument value.

Another: wrapper class (integer, etc.): or passed by reference, because the wrapper class is immutable, creates a new value to assign to it. such as Integer a = 1;integer B = a;b++; (a=1,b=2)

16, data conversion from low-precision to high-precision automatic conversion, Char will be converted to the corresponding ASII code, the basic data type and Boolean cannot be converted to each other. When the operation is performed, the number of symbols is first converted to the int type. The round function is equivalent to adding 0.5 and then rounding down, and the shift operation for negative numbers is 1 at the highest bit. and first converted to a 32-bit int value for interception.

17, English is 1 bytes, Chinese 2 bytes

18. Creation and storage of string

New amounts are generated as soon as you use new (that is, when you define a variable, the reference address is different).

The JVM has a string constant pool, and if the created string is not in the pool, the object is created and added to the pool, returning its reference. When the new string is called, a string constant in a pool is passed.

19, "= =" is used to compare two variables corresponding to the memory stored in the same value, cannot compare the internal contents of the referenced object is equal

The Equals:object method, which does not overwrite the same case as = =, is to compare whether the reference variable points to the same object.

Hashcode: An int value that returns an object (seemingly no longer the value of a reference variable, but rather a pointer to the object itself) in an in-memory address translation.

String is an immutable class, StringBuffer (character buffer) is a mutable class, multithreaded; StringBuilder is a single thread

20. The array is provided with length to obtain the lengths, the character A is obtained by the length () method, and the generic collection is obtained by size.

Finally is executed before the return statement, and if there is a return in Finally, overwrite the other. In addition, return returns when the value of a copy is copied to the stack, and then return the variable. If you reference a type of data, modifying the variable before the end of the statement affects the returned value, and the basic data does not.

Finally, it is not necessarily performed, such as an error before forcing the exit or entering Trycatch.

Java Fundamentals 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.