Details! Focus! Easy wrong point! --Interview Java Basics (i)

Source: Internet
Author: User
Tags float double

Today to share the Java focus on the wrong part of the point, but also the interview needs of all students to prepare, welcome to communicate correct.

The main method in 1.java is a static method, that is, the code in the method is stored in a static storage area.

2. Any static code block will be executed before the main method.

Initialization order of 3.java programs: Principle: Static takes precedence over non-static and is initialized only once; the parent class takes precedence over the child class and is initialized in the order of member definitions.
Example order: The parent class static variable, the parent class static code block, the subclass static variable, the subclass static code block, the parent class non-static variable, the parent class non-static code block, the parent class constructor, the subclass non-static variable, the subclass non-static code block, the subclass constructor.

A file in 4.java can define multiple classes, but only one class will be publicly decorated, and the class name and filename must be the same, and each class generates a bytecode file.

5. Features of the constructor: 1) The name must be the same as the class name, 2) The constructor cannot be inherited, cannot be overwritten, but can be overloaded, 3) subclasses can display the constructor of the parent class through the Super keyword, but when the parent class does not provide a parameterless constructor, The constructor of the subclass must display the constructor of the calling parent class.

The interface constants in 6.java use the public static final decoration by default.

When working with basic data types, 7.java is passed by value, while others are passed by reference.

The difference between a 8.clone method, a deep copy, and a shallow copy: a deep copy copies the objects that are referenced by the copied objects once, and shallow assigns only the objects that are considered for the assignment, and does not copy the objects that he refers to.

9. Three methods of obtaining classes: 1) class.forname (); 2) class name. Classes; 3) instance. GetClass ().

10. Four ways to create objects: 1) by new instantiation, 2) through the reflection Mechanism, 3) through Clone (), and 4) the object is created by deserialization.

11. When the member variable defined in the subclass and the member variable defined in the parent class are the same, the child class member variable overrides the member variable of the parent class and does not inherit.

The 12.java provides two mechanisms for polymorphism, compile-time polymorphism, and run-time polymorphism. Compile-time polymorphism is implemented through method overloading, and runtime polymorphism is achieved through method overrides.

13. Method overloading and method overrides: Overrides are the relationships between subclasses and parent classes, are vertical relationships, overloads are relationships between methods in the same class, and are horizontal relationships. Override requires the same parameter list, overloading requires a different list of parameters.

14. The similarities and differences between abstract classes and interfaces: 1) abstract can only be used to modify a class or method and cannot be used to modify a property. 2) An abstract class represents an entity, and an interface represents a concept.
3) As long as a class containing an abstract method must be declared as abstract class 4) subclasses provide concrete implementations for all abstract methods in the parent class, or they are abstract classes.
The same point: 1) Neither the interface nor the abstract class can be instantiated 2) the implementation class of the interface or the subclass of the abstract class can only be instantiated after implementing the abstract method among them.

Different points: 1) The interface is only defined, its methods can not be implemented in the interface, only the class implementing the interface can implement the method defined in the interface, and the abstract class can have a definition and implementation, that is, the method can be implemented in the abstract class
2) interfaces need to be implemented implements but abstract classes need to be inherited extends, a class can implement multiple interfaces, but a class intelligence inherits an abstract class.
3) The interface emphasizes the realization of the specific function, the design concept is has-a, and the abstract class emphasizes the relationship, and its design concept is is-a
4) The member variable defined in the interface defaults to public static final, can only have static data members that cannot be modified, and must be assigned an initial value, and all member methods must be public and abstract.
Abstract classes can have their own data members, or they can have a cost-abstract method, the member defaults to default, can also be defined as private,protected and public.
When the function needs to be accumulated, use the abstract class, and do not need to accumulate when using the interface.
5) The interface is used to implement more commonly used functions, to facilitate future maintenance or to add a delete method, the abstract class is more inclined to act as a public class role.
An interface can inherit an interface, an abstract class can implement an abstract class, an abstract class can inherit a concrete class, and an abstract class can have a main method of a static class.

15. Inner class: mainly divided into four kinds of static inner class; inner class of member; local inner class; anonymous inner class
1) A static inner class cannot have the same name as an external class, cannot access the ordinary member variables of an external class, can access only static members and static methods in the outer class, and non-static inner classes cannot have static members.
2) Local inner class like local variables, cannot be public protect private and static decoration
3) An anonymous inner class is an inner class that does not have a class name, cannot use the keyword class extends implements has no constructors, and he must inherit other classes or implement other interfaces.

The 16.this and Super:this pointers point to the current instance object, and super can be used to access the parent class's methods or member variables.
17. When a subclass's constructor needs to call the parent class's constructor, super () must be the first statement in the constructor.

18.final,finally,finalize differences:
FINAL:1) Final is used to declare properties, methods, classes, non-mutable properties, methods not overwritten, and classes cannot be inherited. (Immutable has two meanings: reference immutable; object immutable.) Final refers to the immutable reference)
2) Final class, the class cannot be inherited, all methods cannot be overridden, but the properties are mutable. A class cannot be declared both abstract and final.
Finally: As part of exception handling, followed by Try/catch and accompanied by a block of statements, indicating that the statement will eventually be executed.
Finalize: Is a method of the object class that, when executed by the garbage collector, invokes the Finalize method that is used to reclaim the object.

19.assert: As a software debugging method, the live function is to check a Boolean expression
The difference between the assert and the C language: Java is assert is the keyword, the C language uses the library function, assert is open at compile time, while the Java language is open at run time.

20.static keywords: primary role: To allocate a single storage space for a particular data type or object, and to implement a method or property associated with a class rather than an object.
1) static member variable: a static member variable belongs to a class that does not belong to an object, there is a copy in memory, and a static variable cannot be defined inside a member function in Java.
2) static member methods: Static methods belong to a class that does not belong to an object, and the This and Super keywords cannot be used in static methods. A very important use of the static keyword is to implement a singleton pattern. (Singleton mode: Hides the constructor, providing a way to statically create the object)
3) Static code block: Not in any one method body and executes only once.

21.switch statement: Support int or int wrapper class integer, some can be implicitly converted to int type such as short byte and char and their wrapper class is also supported. In addition, string types are supported in Java7.

22.volatile: is a type modifier that is designed to modify variables that are accessed and modified by different threads. Each time the system uses it, it is extracted from the corresponding memory.

23.instanceof: is a two-dollar operator in the Java language, and his role is to determine whether a variable of a reference type points to an object that is an instance of a class.

There are eight basic data types in 24.java: byte short int long float double char Boolean (note that the default declared decimal number in Java is double type, so float a=1.1 is not legal)

25. Immutable classes: All basic types of wrapper classes are immutable classes (references are immutable).
Create a immutable class Five principles:
1) All member variables in the class are decorated by private.
2) There is no way to write or modify member variables in a class, only one generation of constructors is provided.
3) Ensure that all methods in the class are not covered by the quilt class (using final to achieve the purpose).
4) If a class member is not an immutable class, then the Clone method is required to ensure that the class is immutable when the member initializes or gets the member variable using the Get method.
5) If it is necessary to overwrite the Equals and Hashcode methods of object.

26. Value passing and reference passing: 1) in a method call, an actual delegate passes its value to the formal parameter, and the parameter knowledge Initializes a temporary storage unit with the value of the argument, although the parameter has a different storage unit than the same value as the argument.
2) The original data type is passed by value when the parameter is passed, and the wrapper type is passed by reference type.

27. Conversion of different data types:
Automatic conversion.
1) The char type is converted to an advanced type and will be dedicated to the corresponding ASC code.
2) The byte char short type is automatically converted to the int type when it participates in the operation. However, the type conversion is not generated when you use + =.
3) Basic data types and Boolean types cannot be converted to each other.
Forced type conversions are required when advanced data types are required to be converted to low-level data types.

28.round Ceil Floor Method: The Round method represents rounding, the Ceil method represents an upward rounding, and the floor method represents a downward rounding.

29.i++ means first using I in giving I self-increment, ++i expression first to I self-increment, in using I.

30.>> and >>>:>> in the right-shift operation, if the number of participants is positive, then the high 0, if negative, then the high 1. >>> is different, regardless of the number of operations is positive or negative, in the execution of the operation will be in the high 0.

Details! Focus! Easy wrong point! --Interview Java Basics (i)

Related Article

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.