Java must back questions and project interview key points

Source: Internet
Author: User
Tags data structures joins md5 set set

A database

1. Often ask the database query, modifications (SQL queries include filter queries, aggregate queries and link queries and optimization issues, handwritten SQL statements, such as four team games, with SQL to show all match combinations; Example 2: Select duplicates and then remove duplicates;) How to encrypt passwords in the database (MD5);

(1) Password encryption of the database: one-way encryption, insert into users (Username,password) VALUES (' Mike ', MD5 (' guessme '));

(2) Bidirectional encryption: INSERT into users (username, password) VALUES (' Mike ', ENCODE (' guessme ', ' Abanaafn '));

(3) SQL filter Query: SELECT * from user where user_id in (select user_id to User group by USER_ID has count (user_id) >1) Order B Y user_id desc;

(4) SQL aggregation query: Select user_id from user group by user_id;

(5) SQL JOIN query: Internal connection. Select S.name,m.mess from student s inner join Mark M on S.id=m.studentid; LEFT outer join: Select S.name, m.mess from stud ENT s left join Mark M on S.id=m.studentid; the right outer join: Select S.name, m.mess from student s right-hand join Mark M on S.id=m.studentid ; full-outer join: Select S.name, m.mess from student s fully join Mark M on S.id=m.studentid;

(6) Team game combination: SELECT COUNT (*) from department as a, department as B a.name<>b.name;

(7) SQL SELECT Duplicate statement: Select ID, name from user where ID in (select ID from user group by ID has count (1) >2); Remove duplicate statements: Select ID FR The OM user group by ID has count (*) >1;

(8) Database optimization: Preparestatement than statement performance, a SQL sent to the server to perform. Involves steps: syntax checking, semantic definition, compilation, and caching. An external check constraint can affect insertions and deletions, and if the program guarantees the integrity of the data, Then remove the foreign key when designing the database. All uppercase SQL statements, especially column names and table names.

2. How to implement the database paging function. SQL statement Complex relational table query, cumulative sum.

How to connect to a database without using a framework.

What are the two interfaces that need to be shut down after the database is connected?

What is the easiest exception to throw when closing a database.

(1) Paging: "SELECT * from User Limit" + (pageNo-1) *pagesize+ "," +pagesize;

(2) Sum: SELECT * FROM user1 Union select * from User2;

(3) Manual connection database: Connection cn=null; PreparedStatement Pst=null; Result Rs=null;try{class.forname (driverclassname); Cn=drivermanager.getconnection (Url,username,password);p st= Cn.preparestatement ("SQL");p st.setstring (1,studentname); Result Rs=pst.executequery (), while (Rs.next ()) {System.out.println ();} catch (Exception e) {e.printstacktrace ();} Finally{if (rs!=null) {rs.close ();} if (pst!=null) {pst.close ()}if (cn!=null) {cn.close ();}}}

(4) Result preparestatement results set and SQL transfer

(5) Exception

3. Advantages and disadvantages of Oracle indexes, views and stored procedures, and what connectors are. What the default port is. MySQL what is left link, right link and inside link. What is the result of querying the left, right, and inner links in the database?

How the database is stored, talk about it?

(1) port: 1521;

(2) The inner join is the same data as the left table and the right table.

Outer connection is divided into: Left outer connection, right outer connection, all outer connection

The left outer join is the left table, to match the right table, the left table has how many data, the result is how many data

Right outer connection is with left outer connection on the contrary, to the right table, to match the left table, right table how many data, the result is how many data.

The number of data bars in all outer joins is not necessarily the same as the combination of left outer and right outer joins.

(3) Oracle index is divided into: Clustered index, nonclustered index, unique index; advantages: Easy to query, in large amount of data sorting more appropriate query; Disadvantages: The query needs to be reordered, reducing efficiency. Physical index disadvantage to establish a low index efficiency, can only build a more convincing;

(4) The connector is "| |" or concat ();

(5) View: It's actually a query SQL statement that displays related data in one or more tables or other views. The view uses the results of a query as a table, so the view can be viewed as a stored query or a virtual table. Views are derived from tables, and all modifications to the view data are ultimately reflected in the base table of the view, which must be subject to the integrity constraints of the base table and trigger that is defined on the base table.

(6) Stored procedures: Oracle has system stored procedures and custom stored procedures, in order to complete a specific function of the set of SQL statements, compiled and stored in the database, the user through a specific stored procedure name to execute

(7) Storage principle: When the user creates an index, Oracle automatically creates an index segment in the table space to store the indexed data;

4. Can I store Chinese characters inside Char?

(1) Char variables are used to store Unicode encoded characters, the Unicode coded character set contains Chinese characters, so you can store Chinese characters, and if a particular character is not included in the Unicode character set, then the char variable cannot be stored. Unicode occupies two bytes, so a char variable is also occupied by two bytes.

Two Java Basics

1. Talk about polymorphic forms of expression.

(1) Overloading, overriding, overloaded overload means that there can be multiple methods with the same name in the same class, but the argument lists for these methods are different

(2) overriding override means that a method in a subclass can be exactly the same as the name and parameters of a method in the parent class. When this method is called by an instance object created by a subclass, the defined method in the subclass is invoked, which overrides the exact same method defined in the parent class. This is also an expression of the polymorphism of object-oriented programming, which can only throw fewer exceptions than the parent class, or throw out the exception that the parent class throws, and the subclass method can have access only larger than the parent class, not smaller. If the method of the parent class is private, then the subclass does not have an overlay limit, and a new method is added to the subclass

2. Data encryption mode. The order of the encryption mode.

(1) Symmetric and asymmetric, sequential: transmission encryption, data storage encryption, data integrity type identification, Key management;

3. Ask the hasshmap underlying data structure, arraylist-linklist difference and why there is such a difference; array comparison method; difference between basic type and reference data type; the difference between the interface and the abstract class;

(1) HashMap is a line program that is not secure, not synchronized.

HashMap allows you to use NULL as the key or value of a table entry

HashMap is actually a combination of an array and a linked list, in the Java programming language, the most basic structure is two, one is an array, the other is an analog pointer (reference), all data structures can be constructed with these two basic structures, HashMap is no exception. HashMap is actually a combination of an array and a linked list.

(2) Difference: ArrayList is the implementation of the data structure based on dynamic array, LinkedList based on the data structure of the list, for random access to get and set,arraylist feel better than LinkedList, because the linkedlist to move the pointer. For new and delete operations Add and remove,linedlist more dominant, because ArrayList to move the data, if only the single data inserted or deleted, ArrayList speed is better than LinkedList. But if the batch random inserts deletes the data, the LinkedList speed is much better than ArrayList.  Because ArrayList each insertion of data, you move the insertion point and all subsequent data. This I did the experiment. In the first 200,000 "records" of ArrayList and LinkedList insert 20,000 data, LinkedList time is about ArrayList 20 1.

4. How to configure the installation JDK. How to determine the success of its configuration.

(1) First install JDK to see your computer's number of digits, choose 32 or 64 JDK version, recommended use 1.6 version above, 1.7 version;

(2) Download JDK installation package from Oracle website.

(3) After downloading the installation package, double-click the installation package to install, the installation path can use the default path.

(4) After the installation is completed, also need to carry out the configuration of environment variables, in the system environment variable user variables add a variable named java_home environment variable, and then fill in the value of the JDK installation directory of the path of the bin folder, such as: C:\ProgramFiles\Java \ jdk1.7.0_79, then add a variable named path, and the variable value is filled in as%java_home%\bin;

(5) A simple Java program can be written to test whether the JDK has been installed successfully: public class Test{public static void Main (String args[]) {System.out.println Test program. ");}} Save the above program as a file with a file name of Test.java. (Note that Test is the public class of the program, must be consistent with the file name, including capitalization) then open the Command Prompt window, the CD to your Test.java directory, and then type the following command: Javac Test.java (carriage return) Java Test At this point, if you see the print this are a test program, the installation is successful, if you do not print out this sentence, you need to carefully check your configuration.

5. Handwritten single case mode (a hungry man and full Han mode) and Factory mode.

(1) Single case A hungry man mode://A Hungry man type single case class. is instantiated when class is initialized
2 public class Singleton1 {
3//Private default constructor
4 Private Singleton1 () {}
5//has been self instantiated
6 private static final Singleton1 single = new Singleton1 ();
7//Static Factory method
8 public static Singleton1 getinstance () {
9 return single;
10}
11}

(2) Lazy mode://lazy type Single case class. Instantiated at the first call
2 public class Singleton2 {
3//Private default constructor
4 Private Singleton2 () {}
5//Note that there is no final
6 private static Singleton2 single=null;
7//Static Factory method
8 public synchronized static Singleton2 getinstance () {
9 if (single = = null) {
A single = new Singleton2 ();
11}
return single;
13}
14}

(3) Factory mode:

Interface ifactory{

Public iproduct createproduct ();}

Class Factory implements ifactory{

Public IProduct createproduct () {return new Product ();}}

public class client{

Public Static void Main (String [] args) {ifactory factory=new factory ();

IProduct product=factory.createproduct ();

Product. Productmethod ();}

6. Create a list by handwriting, define list, generics.

(1) List list=new ArrayList ();

(2) List<student> list=new arraylist<student> ();

(3) Student s=new Student ();

(4) List.add (s);

7. Security: The difference between Hassmap and hasstable. That's not safe. Why. How to facilitate hashmap. Threading aspect: Threads have several states. Talk about the security problem of multithreading; ask for threads and sync. Write a producer and consumer model; Consider the problem of high concurrency.

(1): Difference: I. Historical reasons: Hashtable is based on the old Dictionary class, and HashMap is an implementation of the map interface introduced by Java 1.2;

(2) two. Synchronicity: Hashtable is thread-safe, that is, synchronous, and HashMap is not secure, not synchronized.

(3) Three. Value: Only HashMap can let you use NULL as the key or value of a table entry

(4) Why? The biggest difference is that the Hashtable method is synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide an external synchronization.

Hashtable and HashMap use the same hash/rehash algorithm, so there's no big difference in performance.

(5) Traversal HASHMAP: Two ways, Map map=new HashMap ();

Iterator Iter=map.entryset (). iterator (); s

Iterator Iter=map.keyset (). iterator ();

(6) Threads usually have five states, created, ready, run, blocked, and dead;

The first is to create a state. In the build thread object, and there is no call to the object's Start method, which is the thread in the creation state of the handwritten string inversion and bubble sort;

The second is the ready state. When the thread object's Start method is invoked, the thread enters the ready state, but the thread scheduler has not set the thread as the current thread at this time and is in a ready state. After a thread is run, it is ready when it comes back from wait or sleep.

The third is the running state. The thread scheduler sets the thread in the ready state to the current thread, at which point the thread enters the running state and starts running the code in the Run function.

Four is the blocking state. When a thread is running, it is paused, usually to wait for a certain time to occur (for example, a resource is ready) before continuing. Methods such as sleep,suspend,wait can cause threads to block.

The five is the state of death. If a thread's Run method finishes or calls the Stop method, the thread dies. For a dead thread, you cannot use the Start method to get it ready

(7) Multithreading security issues: In summary, multiple threads in the execution of the same piece of code, each execution result and single-threaded execution results are the same, there is no execution results of the two semantics, can be called thread-safe. Thread-safety issues are mostly caused by global variables and static variables, which are generally thread-safe when multiple threads perform only read operations on shared data, write-only operations, and thread synchronization to resolve thread-safety issues when multiple threads perform write operations.

(8) Threading and synchronization: Describes the two characteristics of Java threads, visibility and ordering. There is no direct data interaction between multiple threads, and the interaction between them can only be achieved through shared variables.

Java allows multithreading concurrency control, when multiple threads simultaneously manipulate a shareable resource variable (such as data deletion and modification),

Will cause the data to be inaccurate and conflict with each other, so join the synchronization lock to avoid being invoked by another thread before the thread completes the operation.

So as to ensure the uniqueness and accuracy of the variable.

(9) Producer and consumer mode: the storage space is full, and the producer occupies it, the consumer waits for the producer to give up the space to remove the product, the producer waits for the consumer to consume the product, thus adds the product to the space. Waiting for each other, resulting in a deadlock.

(10) Mode: 1.wait () and notify (); 2.await () and signal (), the way of the lock; 3. how to block queues;

(11) High concurrency: means of cutting (longitudinal, transverse) and load balancing. Vertical separation is mainly divided by business (function), this is the so-called service-oriented architecture, the horizontal separation of more, mainly rely on the processing of object property load Balancing can be mirrored (deployment) distribution (the same function deployment of several) and computing distribution (a problem divided into several child problems on different machines run, Then merge the results). Of course, these methods can be synthetically used, and finally can be made into multiple pipeline distributed computing mode;

8. List, map and set when used. The difference and connection between each other.

(1) List is the order of the object, you can have the same object, through the index access; Generally, when you can use the array directly, there is a use list

(2) Set set: The set is a disorderly storage object, which can not have duplicate objects (only, recall the high school mathematics learning of the set characteristics), the collection has no index, can only be accessed; objects that are not repeatable (in order unimportant) are generally used for storing unordered

(3) Map mapping: Mapping, which holds the mapping of keys and values, where keys are unique (cannot have duplicate objects), and the value can have duplicate object, save time, need to specify key and corresponding value, take time can be taken according to the key name to value, also can traverse; usually used for storing key-value pairs with corresponding relationships;

(4) The differences and relations between the three: all three are interfaces, list and set have similarity, they are a single column of the collection of elements, List,set is inherited from collection, and map is not, list can have duplicate elements, have successively, set inside not allowed to have duplicate elements, and unordered, Map saves Key-value value, value can be multivalued.

9. What are the common data types in Java and what are the corresponding wrapper classes? An implicit type of java. Assert when to use.

(1) int, double, float, long, short, Boolean, Byte, Char

(2) Integer.double,float,long,short,boolean,byte,characher.

(3) The implicit type of Java is that Int,byte,short,char can be implicitly converted to int,

(4) Generally speaking, assertion is used to guarantee the most basic and critical correctness of the program. Assertion checks are typically opened during development and testing. In order to improve performance, the assertion check is usually closed after the software is released;

What are the methods in the object type.

(1) equals (), hashcode (), Wait (), toString (), Finalize (), notify (), Notifyall (), Wait (),

The difference between final, finallly and finalize.

(1) Final used to declare properties, methods, and classes, respectively, indicating that the property is not mutable, the method is not overridden, and the class is not inheritable.

Internal classes to access local variables, local variables must be defined as final types, for example, a piece of code ...

Finally is part of the structure of the exception-handling statement that always executes.

Finalize is a method of the object class that will invoke this method of the reclaimed object when the garbage collector executes

The difference between LinkedList and ArrayList. An inherited interface.

(1) ArrayList is used to store data in an array that is larger than the actual stored data in order to increase and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the insertion data is slow

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.