Advanced Java Knowledge

Source: Internet
Author: User
Tags comparable

Common exceptions:

Null pointer exception nullpointerexception, a call to an uninitialized object or an object that does not exist, or a property or method that accesses or modifies a null object;

Cannot find the class name exception classnotfoundexception, does not exist, the development environment has been adjusted or, such as the root structure of the class, the compile run time changes, etc.

The class name is not legal exception illegalagreementexception, the method is passed an illegal or incorrect parameter;

Input mismatch exception inputmismatchexception, thrown by scanner the table gets content that is inconsistent with the expected type of pattern or the content exceeds expectations; Illegalaccessexception, the application attempts to create an instance, set or get a property, Or calls a method, but the currently executing method cannot access the definition of the specified class, property, method, or construction method;

Classcastexceptiom, thrown when attempting to convert an object to a subclass other than an instance;

SQLException, database access or other error message exception;

IOException, an I/O exception occurs.

Differences between run-time exceptions and check-out exceptions:

Run-time exception, do not require the program at compile time to deal with the exception, can also be compiled through;

Check the exception is also called non-running exception, the programmer must be processed at compile time, otherwise the compilation does not pass.

The difference between ArrayList and linklist in "Enterprise interview often":

The former uses the array to store sequentially, when inserting or deleting data, it is necessary to move data elements in bulk, so the performance is poor; When querying data elements, the array is continuously stored and can be accessed by subscript, so it is efficient to traverse elements or randomly access elements. Linklist is the opposite.

The pros and cons of sequential storage structures and chained storage structures:

The former advantages: Save storage space (the allocated storage unit is used to store the data of the node, the logical relationship between the nodes does not occupy additional storage space), increase the access speed (storage cell storage can realize the random access of the node); Fast search speed. Cons: Slow insertion and deletion

The latter advantage: fast insertion and deletion. Cons: Large footprint (each node consists of data fields and pointer fields); The lookup is slow (looking through the pointer one by one).

Stack and queue two data structure features:

Stack stack: Advanced post-out or LIFO, a special linear table that can only be inserted and deleted at one end.

Queue queues: First-in or last-out, only delete operations are allowed on the team header and insert operations at the end of the team.

Binary (binary) Find pros and cons and their scope of application:

Advantages: Fewer comparisons, faster lookups, and better average performance. Disadvantage: Require unknown origin data to be ordered structure; Insert Delete is difficult.

Scope of application: Data is infrequently changed and frequently searched.

The difference between the set interface and the list interface:

The set interface is unordered and does not allow duplication so that data elements in the set interface cannot be accessed through an index;

The list interface is ordered, allowing duplication, and the user who operates this interface can precisely control each element in the sequence.

The difference between collections and collection:

The Collections Tool class is a collection object tool class that provides tool methods for manipulating collections, such as sorting, copying, and reversing sorting.

The array tool class, which is a tool class for arrays, provides a tool method for manipulating arrays, such as sorting, binary lookup, and so on.

Collection is the most basic collection interface, inherited from the Iterable interface, a collection represents an object, each object is an element in the collection.

The difference between comparable and comparator:

The Comparabletreeset collection is sorted by default in natural order, and the comparison between elements within the set is done by the CompareTo (Object O) method, which is called an internal comparator; string and various wrapper classes have implemented the comparable interface The objects in the TreeSet need to implement the comparable interface.

Comparator is an external comparer that is used when the objects in the collection do not support self-comparison or self-comparison functions that do not meet the needs of programmers; Use the sort (List list,comparator C) method with collections Compared with the internal comparator comparable, the reusability is good.

Generics: Resolves procedural readability and stability issues when forcing type conversions.

Generics cause: The various types of objects that are loaded into the collection are treated as object, losing their own type, and the need for type conversion when fetching objects from the collection is inefficient and error-prone.

To make a Java program cross-platform, you need to be aware of the file operations:

When the file class creates an abstraction of a path, it is guaranteed to create a file class that is also cross-platform, and note the settings of the different operating systems for the files path. Under Linux and UNIX, the path delimiter is ":", the path delimiter is "/", and the window system has a backslash "\" or double slash "//".

The difference between a byte stream and a character stream, and the benefits of a character stream:

BYTE stream: Processing units are bytes, commonly used to deal with music picture files and other binary files, 1 characters will be 2 times before operation.

Character stream: The processing unit is a Unicode encoded character; 1 kanji only need to be manipulated once.

Character Stream Benefits: in the operation of Chinese characters, internationalization and other aspects have advantages.

Advantages and disadvantages of static import and static import:

Static import: Used to specify a static property or method of a class, or all static properties or methods.

Pros: Omitting system and integer writes, code writing is relatively straightforward.

Cons: The code is relatively simple while reducing the readability of the code, possibly causing static import conflicts, such as importing both the integer and long classes, the compiler does not recognize the Max_value constant attribute in both classes.

Why use buffered streams:

Byte stream and character stream are unbuffered input and output streams, each read and write to the operating system processing, each read and write may cause disk hardware read or write or network access to take up a large number of operating system resources, affecting the efficiency of the system may also have a significant impact on performance.

A buffered stream is an adorner class that is designed to allow the stream of bytes of the original stream to be added to the buffering function. In the case of character stream, the characters buffer stream reads and writes characters from the character stream, does not require the system to be processed at once, but buffers some characters to achieve efficient reading or writing according to the specified number of characters, rows, etc. The size of the buffer can be specified (buffered stream construction method specified).

In some cases, it is not necessary to wait until the buffer is full to write to the file system, such as when processing some critical data, you need to immediately write these critical data to the file system, you can call the flush () method, manually refresh the buffer stream.

Calling a Flash () method refreshes all buffers in the writer and outputstream chains.

Adorner mode and adapter mode:

The use of the adorner pattern in practice: Object references are passed into the adornment class, dynamically adding additional functionality to these objects, creating new objects that are actually required for the byte stream and character stream.

Adapter mode: Converts a byte stream into a character stream, in effect using a design pattern. The intention is to convert the interface of one class into another interface that the user wants, which makes it possible for those classes that would otherwise be incompatible with the interface to work together.

XML represents the benefits of data and the scope of application of XML documents:

Advantages: Simple, flexible, good interactivity, scalability.

Application scope: Storage data, System configuration, data exchange.

What are the differences between parsing XML document technologies and their:

Dom parsing: The DOM is a standard solution that provides standard parsing methods.

Dom parsing has been unsatisfactory because DOM parses an XML document, reproduces all of its contents one-time, and constructs a node tree that is quasi-left in memory, which can cause performance problems if the XML document that needs to be parsed is too large or only interested in parts of the document.

Sax parsing: is both an interface and a package. Is event-driven when parsing XML,

Sax parsing works by sequentially scanning the document, notifying the event handler when the document starts and ends, the start and end of the element, and the event handler, and then continues the same scan until the end of the document.

Sax parsing disadvantage: In order to parse a document with sax, it is necessary to implement multiple event handlers to handle the events that may be triggered, which is relatively complex for programmers to manipulate.

Advanced Java Knowledge

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.