Summary of abstract classes:
· The biggest difference between abstract classes and ordinary classes is that there are abstract methods in the abstract class, so in the abstract class
You can define attributes, construct methods, and so on
· The abstract class declaration is not allowed to use final, the abstract class must require a subclass, and the final defined class is not able to have subclasses.
· Even if there is no abstract method in the abstract class, it cannot be directly instantiated.
The main method in JAVA can be said to create a long, its composition has many keywords, the following to analyze each keyword:
· Public: refers to the common;
· Static: Methods defined with static must be called by the class name;
· Void: Is the starting point of all, as long as the beginning of the return of No;
· Main: is a system-defined method name, as long as the execution class, then find main;
· String args[]: An array of string objects used to receive initialization parameters.
There are eight wrapper classes available in Java: Byte (Byte), short (short), int (Integer), long (long),
Float (float), double (double), Boolean (Boolean), char (Character).
However, for the wrapper class, it can be divided into two categories:
· Object type wrapper class: Boolean, Character;
· Numeric wrapper class (subclass of Number): Byte, Short, Integer, Long, Float, Double;
For the wrapper class, there are two most important operations:
· Boxing: The basic data type into the form of wrapper class object, often use the construction method of each wrapper class;
· Unpacking: Extracting data from the wrapper class that contains the underlying data type, using the methods in the number class;
All exceptions belong to Throwable subclasses. There are two sub-classes under Throwable:
· Error: Refers to the JVM error, at this time the program has not been properly executed, such errors generally we can not handle;
· Exception: Refers to the error (exception) that occurs in the program, which the user can handle.
Exception is the largest sum of exceptions that we can handle in our development. The maximum parent class for the exception.
Why do I have to start multithreading with the Start () method? Direct call to run () why not?
The Java program itself is limited by the existence of single inheritance, if now a class has inherited the Thread class, then this class is
Not be able to inherit other classes, so in order to solve such problems, in the implementation of multithreading also provides a Runnable
interface, using interfaces to avoid the limitations of single inheritance.
Multithreading using the Runnable interface is more convenient than inheriting the thread class for multithreading, because it effectively avoids
The limitation of single inheritance, and regardless of how it is used, requires that it must start multithreading using the Start () method in the Thread class.
In addition to the limitations of single inheritance, in the development of the use of the Runnable interface can also be more convenient to represent the concept of data sharing.
TreeSet relies on the comparable to differentiate duplicate data;
HashSet relies on hashcode (), Equals () to differentiate duplicate data
Duplicate data is not allowed to be stored in Set.
Question one: About super and this issue
· Super calls the method or property of the parent class, and this invokes the method or property of this class;
· Super calls the parent class constructor method when it must be placed in the first row of the subclass construction method, and this () calls this class constructor method, also
Must be placed on the first line of the construction method, so "super ()" and "This ()" cannot appear at the same time when the construct is called;
· This exists with a concept that represents the current object, and super does not have such a concept
Question two: What is the difference between a method override and a method override?
· Method overloading (Overloading): The method name is defined in the same class, and the contents and the number of parameters are different.
There is no restriction on the access to law;
· Method Overwrite (Override): In the inheritance relationship, the subclass defines the same method name as the parent class, the type and number of arguments,
return value, you need to consider permissions issues, that is, the overridden method cannot have more restrictive access control permissions than the parent class.
Interview question: Please explain the difference between "= =" and Equals () in String.
· "= =": Belongs to the Java-provided relational operators, mainly for the object's address numerical comparison;
· Equals (): A method in the string class that is primarily a comparison of string content.
In future development, be sure to use equals () to compare strings
Interview question: Please explain the difference between the two instantiation of a String class object?
· Construction method: Generates two heap of memory space, one block will become garbage, and will not be automatically pooled, the user can
The Intern () method is manually entered into the pool;
· Direct assignment: Only one heap of memory space is generated and can be automatically pooled
Interview question: Ask Exception and runtimeexception have those difference?
· Exception is the parent class of runtimeexception;
· Other subclasses (exceptions) defined by Exception require mandatory processing, while runtimeexception can be used by the user
Selective processing.
Interview question: Please explain the difference between enum and enum?
· Enumerations defined with the Enum keyword are equivalent to using a class to directly inherit the enum class;
Interview question: What is the difference between the Thread class and the Runnable interface? (Please explain the difference between the two ways to implement multithreading)
· The Thread class is a subclass of the Runnable interface;
· If you want to implement multi-threading, you must have a thread principal class, and the principal class can inherit the thread class or implement Runnable
interface, but the implementation interface can effectively avoid the single inheritance limitation;
· The multi-threaded class implemented by Runnable can be used to express the concept of data sharing more conveniently.
Interview question: Please explain the difference between String and StringBuffer?
· Once a String is declared immutable, the contents of the stringbuffer can be changed;
Interview question: Please explain the difference between StringBuffer and StringBuilder?
· The methods defined in the StringBuffer class are synchronous methods, and the methods defined by StringBuilder are asynchronous methods;
· StringBuffer operational data is more secure but poorly performing, and StringBuilder lacks security in data operations to
is high performance.
Interview question: What is a GC? How does it work?
· GC refers to a garbage collector;
· The GC is automatically executed by the JVM on an irregular basis, or directly by invoking the GC () method in the Runtime class.
Interview question: Please explain the difference between final, finally, finalize?
· Final: is a keyword that defines a class that cannot be inherited, a method that cannot be overwritten, and a constant;
· Finally: is the exception processing of the unified export, keywords;
· Finalize: Is a method of the object class that is used to perform the processing operations before objects are reclaimed.
Interview question: Please explain the difference between comparable and Comparator?
· Java.lang.Comparable is the default implementation of a good interface at the time of class definition, with only one compareTo () method;
· Java.util.Comparator is the need to define a comparison rule separately, which belongs to the salvage function operation.
Interview question: Please explain the difference between ArrayList and Vector.
· These two classes are subclasses of the List interface;
· The Vector class is provided at JDK 1.0, and the method of operation provided is synchronous, so it is thread-safe
The Operation class;
· The ArrayList class is provided at JDK 1.2, and the method provided is asynchronous, so it belongs to the non-linear
Process-safe Operation classes.
If later in development, 90% of the cases are considered ArrayList.
Interview question: Please explain the difference between HashMap and Hashtable?
· HashMap is provided at JDK 1.2 using asynchronous processing, so it is a non-thread-safe operation.
At the same time, NULL can be saved in HashMap;
· Hashtable is provided at JDK 1.0, using synchronous processing, so it is a thread-safe operation, but
is not able to save null in Hashtable.
In the actual development, HASHMAP save the data because there is no limit, so it is more convenient, then the development of the future
In most cases, the HASHMAP sub-class operation will be preferred.
Some small knowledge and interview questions in Java