Java knowledge Summary-CoreJava

Source: Internet
Author: User

I think the summary of Java on the Internet is very useful and I will share it with you .....

If you have any mistakes, you are welcome to criticize them.

1JavaBasic data type and number of digits, javaBasic Data Type: 4Class 8Type

Integer type: byte (1 byte), short (2 byte), int (4 byte), long (8 byte)

Floating point type: float (4 byte), double (8 byte)

Character Type: char (2 byte)

Logical type: boolean (false/true 1 byte)

2Speak 5Startup exception

RunTimeException

------ NullPointerException

------ ArrayIndexOutOfBoundsException

------ ClassCastException

------ NumberFormatException

3 HashMapAnd HashTableDifferences:

1 HashMap allows null key-value pairs and HashTable does not

2HashMap is NOT thread-safe, and HashTable is

3HashMap implements the Map interface directly. HashTable inherits the Dictionary class.

4.ArrayList, Vector, sorted listStorage Performance and differences

They all implement the List interface.

Both ArrayList and Vector are implemented based on arrays.

The sort list is based on a two-way cyclic linked list (low search efficiency and easy to add and delete)

ArrayList is NOT thread-safe, while Vector is thread-safe. ArrayList is higher than Vector at all speeds.

5.CollectionAnd CollectionsDifference

Collection is the upper-level interface of the Collection class. Its inherited interfaces include Set and List.

Collections is a help class for collection classes. It provides a series of static methods to perform operations such as search, sorting, and thread security on various sets.

6 List, Map, SetWhat are the features of the three interfaces when accessing elements?

A List holds elements in a specific order, and can contain duplicate elements.

Set cannot hold repeated elements, internal sorting

Map stores the key-value, which can be multiple values.

7 final, finally, finalizeDifference

Final is used to declare attributes. Methods and classes indicate that attributes are unchangeable, methods cannot be overwritten, and classes cannot be inherited.

Finally is part of the structure of the exception handling statement, indicating that it is always executed

Finalize is a method of Object class. Other resources are recycled during garbage collection, such as closing files.

8 OverloadAnd Override. OverloadCan the return value type be changed?

Override and Overload are different manifestations of Java polymorphism.

Overriding is a manifestation of the polymorphism between the parent class and the subclass. the type of the method name and the return value type of the parameter list must be consistent with the method of the parent class.

Overload Overloading is a manifestation of polymorphism in a category. The overload method can change the return value type.

9Summarize the Bubble Sorting in one sentence

Compare two adjacent numbers in sequence, place decimal places in front, and place large numbers in the back.

10Two ways to implement thread security

1) synchronized method: the synchronized method is declared by adding the synchronized keyword to the method declaration.

2) Synchronized block: declare synchronized with the synchronized keyword

11Let's talk about "="And equal ()What are the differences between methods in string variable operations?

"=" Compares the addresses of two string objects. equal () compares the specific values of two strings.

12 sleepAnd waitWhat are the differences between methods?

Sleep is a Thread method. As a result, this Thread suspends the execution for a specified time and gives the execution opportunity to other threads. However, the monitoring status remains unchanged and will be automatically restored. Calling sleep does not release the object lock.

Wait is an Object method. Calling the wait method for this Object causes this thread to discard the Object lock and enter the waiting lock pool for this Object. Only the notify method (or notifyAll) is issued for the Object) then this thread enters the object lock pool and prepares to get the object to enter the running state.

13 &And &&Difference

& Bitwise OPERATOR: Non-short-circuit operator. It returns results only after all the conditions are executed.

& Logical operation (and): short-circuit operator. If the operator does not meet the conditions, terminate the program execution immediately.

14 errorAnd exceptionDifference

Error: indicates that recovery is an impossible serious problem, such as memory overflow, which is not expected to be processed by the program.

Exception: An Exception occurs when the program runs properly.

15Please state the thread synchronization method you know about the lock

Wait (): puts a thread in the waiting state and releases the lock of all held objects;

Sleep (): It is a static method that puts a running thread in Sleep state. To call this method, capture InterruptedException exceptions;

Y (): Wake up a thread in the waiting state. Note that when this method is called, it cannot actually wake up a thread in the waiting state, instead, the JVM determines which thread to wake up, not by priority.

NotityAll (): Wake up all threads in the waiting state. Note that it is not to lock all wake-up threads an object, but to make them compete.

16.Network Programming involves concurrent servers, using multiple processes and multithreading. What is the difference?

1) process: the child process is a replica of the parent process. The child process obtains the replica of the Data Space heap and stack of the parent process.

2) thread: A thread is a concept closer to the execution body than a process. It can share data with other processes of the same process, but has its own stack space, independent execution sequence

Both of them can improve program concurrency and improve program running efficiency and response time.

The use of threads and processes has their own advantages and disadvantages: the thread execution overhead is small, but it is not conducive to resource management and protection; while the process is opposite, the thread is suitable for running on SMP machines, the process can be migrated across machines.

17What is reflection?

During running:

1. You can know the attributes and methods of any class.

 

2. Any method of this object can be called for any object.

This kind of dynamic information and the function of dynamically calling object methods become reflection.

Functions provided by the Java reflection mechanism

1. determine the class of any object during runtime

2. construct any class objects during runtime

3. Judge and call the member variables and methods of an object at runtime.

4. Generate a dynamic proxy

18Basic concepts of threads, the state of threads, and the relationship between States

The newly created thread (Born) is in the new State.

Ready is in the Ready state after the thread is created, waiting for the start () method to be called

The Running thread enters the Running status when it starts execution.

You can use the Sleeping () method to suspend the execution of Sleeping threads. After sleep, the thread enters the ready state.

Waiting: If the wait () method is called, the thread is in the Waiting state. Used when two or more threads run concurrently.

When the thread is temporarily stopped or interrupted, the thread is Suspended.

Blocked is called blocking when the thread waits for an event (for example, an input/output operation ).

After the run () method has been executed or its stop () method is called, the thread is in the Dead state.

19Description JVMLoad classFile principle and mechanism

In JVM, class loading is implemented by ClassLoader and its subclass. java ClassLoader is an important java runtime system component. It is responsible for finding and loading classes of class files at runtime.

20What are triggers and stored procedures?

A trigger is a block stored in the database. Once the block is constructed, it can be executed multiple times and called when the trigger event occurs. A trigger event refers to operations on data in a table, such as insertion, deletion, and modification.

Stored Procedures store commonly used or complex tasks in advance with SQL statements and a specified name, to enable the database to provide services with the same functions as the predefined stored procedure, you only need to call execute to automatically complete the command. My understanding is a collection of SQL statements that can be used to create complex queries and compile and run them. Therefore, after a single run, it is much faster to run the query later than to execute the SQL statement separately.

21What is a callback function?

A program S (Student. main) calls A method (sort) in service program A (Arrays), and the sort method of service program A calls A method (compareTo) in turn at some time. In this case, compare is called the callback method of S.

Example: public class Student implements Compareble {

Private int id;

Private String name;

Private int age;

Private int score;

 

// Constructor

// Getter/setter Method

// Callback Method

Public int compareTo (Object obj ){

Return

This. id-(Student) obj). id;

}

}

Student s1 = new Student (1, "a", 18, 89 );

Student s2 = new Student (2, "a", 18, 89 );

Student s3 = new Student (3, "a", 18, 89 );

Student [] arrs = {s1, s2, s3 };

Arrays. sort (arrs );

22Traverse all. java?

Public void listFiles (String path ){

File dir = new File (path );

Files [] files = dir. listFiles (new FileFilter (){

Public boolean accept (File f ){

Return f. getName (). endWith (". java ");

}

 

});

For (File file: files ){

System. out. print (file. getName ());

}

 

}

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.