This Java interview questions spent three months to sort out, are summed up in their own work, remember how much to write, I hope this information can help you, at the end of the article there is the way to get the rest of the information.

Redis12 interview questions

1. What is Redis?

A: Remote Dictionary Server(Redis) is an open source, network-enabled, memory-based, persistent, journalized, key-value database written in ANSI C, with multiple language apis. It is often referred to as a data structure server

2. What data structures does Redis have?

String, dictionary Hash, List List, Set Set, ordered Set SortedSet. If you are an advanced Redis user, you also need to add the following data structures HyperLogLog, Geo, Pub/Sub. If you say you’ve played with Redis Modules, like BloomFilter, RedisSearch, redis-ML

3. What are the characteristics of Redis?

(1) support a variety of data structures, such as String, list, dict, set, zset, hyperloglog, cardinality estimation

(2). Support persistent operation, aOF and RDB data can be persisted to the disk, so as to carry out data backup or data recovery and other operations, a better means to prevent data loss.

(3) Data Replication is supported. Data can be synchronized and replicated in real time through the master-slave mechanism. The master-slave mechanism is an important means for Redis to implement HA. Single-process requests, all commands are executed sequentially, and data consistency does not need to be considered in concurrent cases.

4.Redis operation is atomic, how to ensure atomic?

For Redis, the atomicity of a command means that an operation is not separable and that the operation is either executed or not executed. Redis operations are atomic because Redis is single-threaded. All apis provided by Redis are atomic operations, and transactions in Redis are meant to be atomic for batch operations. Are multiple commands atomic in concurrency? Not necessarily, change get and set to single command operation, incr. Transactions using Redis, or Redis+Lua==.

5. Internal structure of Redis

(1). Dict is essentially a data structure for maintaining the mapping relationship between key and value, which is similar to Map or dictionary in many languages. It’s essentially Searching in the algorithm

SDS is the same as char *. It can store arbitrary binary data. It cannot be identified by the character ‘\0’ like the C language string, so it must have a length field.

A skiplist is a simple, single-layer, multi-pointer linked list that is as efficient in lookup as an optimized binary balanced tree and more efficient than the implementation of balanced trees.

Ziplist is an encoded list. It is a sequential data structure composed of a series of specially encoded contiguous memory blocks.

6. How many Redis configuration and persistence schemes are there?

The following two

RDB way

AOF way

What is RDB mode?

Yes RDB Yes Snapshot the database status in memory RDB mode: The RDB file is a compressed binary file that restores the state of the database when the RDB file is generated (by default, persisted to the dump. RDB file, and automatically read the file after Redis restarts). Typically 10 million string keys, 1GB snapshot file, synchronization time to memory is 20-30 seconds)

RDB generation mode:

The SAVE command blocks the Redis server process until the RDB file is created. The server cannot process any command requests while the server process is blocked. The BGSAVE command gives birth to a child process, which then creates the RDB file. The server process (the parent process) continues to process the command requests. BGSAVE and SAVE commands sent by the client are rejected by the server until the RDB file creation is complete

2, through the configuration of automatic generation can set the server configuration save option, let the server automatically execute a BGSAVE command at intervals, you can set multiple save conditions through the save option, but as long as any one of the conditions are met, the server will execute the BGSAVE command

7. Have you ever used Redis distributed lock? What is it?

Use setnx to fight for locks, and use expire to add an expiration time to locks in case they are forgotten to release.

You will be told that you answered well, and then asked what happens if the process crashes after setnx before expire or if maintenance needs to be restarted?

This is where you respond with surprise: Oh, yeah, the lock will never be released. The next thing you need to do is grab your head, pretend to think about it for a moment, as if you were thinking about the next result on your own initiative, and reply: I remember that the set directive has very complicated parameters. It should be possible to combine setnx and EXPIRE into one directive. The other side will smile, the heart began to say: HMM, this boy is not bad.

8. There are 100 million keys in Redis, and 10W of them start with a fixed, known prefix. How do I find all of them?

Use the keys command to scan out a list of keys for a given pattern. If the redis is providing services to online businesses, what is the problem with using keys? This is the time to answer a key redis feature: Redis single threaded. The keys command causes the thread to block for a period of time and the online service to pause until the command is executed. In this case, scan command can be used. Scan command can extract the key list of the specified mode without blocking, but there will be a certain probability of repetition. It is ok to perform deduplication on the client, but the overall time will be longer than that of direct keys command.

9. If a large number of keys need to be set to expire at the same time, what should I pay attention to?

If a large number of key expiration times are set too centrally, redis may experience a temporary lag at that point in time. It is generally necessary to add a random value to the time to spread out the expiration time

10. Do you know the synchronization mechanism of Redis?

From the synchronization. During the first synchronization, the primary node performs a BGSave and records subsequent modifications to the memory buffer. After the synchronization is complete, the RDB file is fully synchronized to the replication node, and the replication node loads the RDB image to the memory. After the loading is complete, the master node is notified to synchronize the modified operation records to the replication node for replay.

11. Have you used Redis cluster? What is the principle of cluster?

Redis Sentinal focuses on high availability and automatically promotes slave to Master in the event of a master outage. Redis Cluster focuses on scalability. When a single Redis memory is insufficient, a Cluster is used to fragment storage.

12. If a large number of keys need to be set to expire at the same time, what should I pay attention to?

If a large number of key expiration times are set too centrally, redis may experience a temporary lag at that point in time. It is generally necessary to add a random value to the time to spread out the expiration time.

Java Basic ten questions:

1. What are the features of object-oriented?

1. Encapsulation: Define self-related properties and methods, hide implementation details, and only provide the simplest programming interface to the outside world.

2. Inheritance: Inheritance is the process of creating a new class by obtaining information from an existing class. Inheritance improves code reuse, and only single inheritance is allowed in JAVA.

3. Polymorphism: Objects of different subtypes respond differently to the same message. Method overload implements compile-time polymorphism (also known as static polymorphism), while method override implements runtime polymorphism (also known as dynamic polymorphism). General polymorphism is implemented by method rewriting.

2, access modifiers, public, private, protected, and don’t write what is the difference between (the default)?

Modifier the current class is the same as the package subclass and other packages

Public √ √ √ √

Protected √ √ √ ×

Default √ √ × ×

Private √ × × ×

Class members default to default when they do not write access modifiers. The default is public for other classes in the same package and private for classes not in the same package. Protected is public for subclasses and private for classes that are not parent-child in the same package. In Java, external class modifiers can only be public or default, and class members (including inner classes) can have the above four modifiers.

Is String the most basic data type?

Answer: No. There are only eight basic data types in Java: byte, short, int, long, float, double, char, Boolean. Except for primitive type and enumeration type, all the other types are reference types.

4. What is the difference between int and Integer?

1. Int is a basic data type, and Integer is a wrapper class for int. The wrapper class provides many operations, such as direct conversion of various types

2. The default value of int is 0, and the default value of integer is null

Integer ranges from -128 to 127. 4. Different storage methods: An INTEGER is actually a reference to an object. Int stores data values directly

5. The difference between & and &&?

The & operator can be used in two ways:

(1) bitwise and;

(2) Logic and.

The && operator is the short-circuit and operation. The difference between logic and short-circuit and is huge, although both require booleans on the left and right sides of the operator to be true for the entire expression. Am& is called short-circuited because if the expression to the left of am& is false, the expression to the right will be short-circuited and not evaluated.

6, Explain the usage of stack, heap and static area in memory.

Variables of primitive data types, a reference to an object, and the field storage of function calls all use the stack space in memory;

Objects created with the new keyword and constructor are placed in the heap space;

The directly written 100, “hello”, and constants are placed in the static section.

Stack space is the fastest to operate but the stack is small. Usually a large number of objects are placed in the heap space. In theory, the entire memory that is not used by other processes or even virtual memory on the hard disk can be used as heap space.

7. Does array have length() method? Does String have a length() method?

Arrays do not have a length() method, they have a length attribute.

String has the length() method. In JavaScript, the length of a string is obtained through the length attribute, which is easily confused with Java.

8. How do I get out of the current multiple nested loops in Java?

A. break B. break C. break D. break You can jump out of multiple loops.

Continue Terminates this loop

9 Can the constructor be overridden?

A: Constructors cannot be inherited and therefore cannot be overridden, but they can be overridden.

10. Two objects with the same value (x.equals(y) == true) can have different hash codes.

A: No, if two objects x and y satisfy x.equals(y) == true, they should have the same hash code. Java rules for eqauls methods and hashCode methods are as follows:

(1) If two objects are the same (equals returns true), their hashCode values must be the same;

(2) If two objects have the same hashCode, they are not necessarily the same.

MySQL 15 问 题 :

1. Database Three paradigms:

The first normal form: atomicity constraint on attributes, requiring fields to have atomicity and cannot be decomposed;

Second normal form: in the first normal form, non-primary key fields can not appear partially dependent on primary keys;

Solution: Eliminating the compound primary key can avoid the occurrence of a section since the addition of a single column of keywords.

Third normal form: Under the second normal form, transitive dependencies cannot occur for fields that are not primary keys. For example, some fields depend on primary keys while some fields depend on field A. This is transitive dependencies.

Solution: Implement an entity information data in a table.

2. Four major features of transactions

(1) atomicity: an indivisible operation unit. All operations in a transaction are either successful; Or back to the state before the transaction was executed

(2). Consistency: If the database is consistent before the transaction, it will be consistent after the transaction;

(3). Isolation: transaction operations are independent and transparent without affecting each other. Transactions run independently. This is usually done using locks. The result of a transaction that affects other transactions will be withdrawn. 100% isolation of transactions requires a sacrifice of speed. (4). Persistence: Once a transaction is committed, the result is permanent. Even if there is a system failure, it can be recovered

MySQL transaction isolation level

(1). Read Uncommitted: Dirty reads are allowed. When other transactions modify data, even if they are not committed, this transaction can still see the modified data values. That is, data that may be read from uncommitted transaction modifications in other sessions

(2). Read Committed: Only data can be Read. Most databases, such as Oracle, default to this level (no repeat reads).

(3). Repeated Read: Data values seen in this transaction remain unaffected by other transactions, regardless of whether or not other transactions modify and commit data.

(4). Serializable: Fully serialized read, each read needs to acquire table-level shared lock, read and write block each other Repeatable read default MySQL database (InnoDB engine)

MySQL > select * from ‘MySQL’;

(1)index —- Common index, data can be repeated without any restrictions. (that is, create indexes against database tables)

(2)unique —-, the value of the index column must be unique, but empty values are allowed; If it is a composite index, the combination of column values must be unique.

(3)primary key —- primary key index, a special unique index, a table can have only one primary key, do not allow empty values, generally create a primary key index at the same time as the creation of the table.

(4) Combined index —- An index created on multiple fields can be used only when the first field is used in the query condition.

(5)fulltext —- fulltext index (basically not used), is for the text field of the large table: char, varchar, text column can create the fulltext index, mainly used to find the key words in the text, not directly compared with the value in the index. Fulltext is more like a search engine and is used in conjunction with the match Against operation rather than the usual WHERE statement plus like.

Note: Full-text indexing currently only MyISAM storage engine supports full-text indexing, InnoDB engine below 5.6 does not support full-text indexing

Indexes can improve the query speed, but it takes time to create and maintain indexes and affects the insert speed. If a large amount of data needs to be inserted, it is recommended to delete indexes first and create indexes after inserting data.

Index validity condition

Let’s say index (a,b,c).

Left-most prefix matching: fuzzy query, using % matching: ‘A %’ will use index, ‘%a’ will not use index

If there is an OR in the condition, the index will not take effect

A and C, A is effective, C is not effective

B and C are not valid

A and B > 5 and C.

Delete, DROP, and TRUNCATE Differences TRUNCATE and DELETE delete data but not table structure. Drop deletes table structure and releases space occupied by it. Data deletion speed. Drop > TRUNCate > DELEteDELETE Is a DML language that requires transaction management and takes effect only after commit. Drop and TRUNCate are DDL languages. The operation takes effect immediately and cannot be rolled back. When you no longer need the table, use drop. Use TRUNCate when you want to keep the table but delete all records; Always with a where clause, use delete.

6. SQL statement classification:

DDL: Data Definition Language (CREATE DROP)

Data manipulation statement (INSERT update delete)

DQL: Data query statement (SELECT)

DCL: data control statement for grant revoke

TPL: Data transaction statement (commit Collback savapoint)

7. What experience do you have in database optimization? Location:

Before the project is transferred from self-inspection to test, the slow query is opened when mysal database is started, and the slow execution statements are written into the log. After running for a certain time, the slow query statements are found by checking the log. Use explain slow query statements to analyze statement problems in detail.

Optimization means:

Create index: create a suitable index, we can now query in the index, query after directly find the corresponding record. Table: when a table of data is more of a list or some more the value of the field and is rarely used, the method of vertical and horizontal table table to t high read/write points: when a server cannot meet the demand, separation by read and write in a way that cluster cache: use redis to cache some commonly used optimization techniques

Varchar (50) = varchar(50);

(1). Differences between varchar and char: char is a fixed length type and varchar is a variable length type.

(2). Varchar (50) in the meaning of 50: a maximum of 50 bytes

(3). Int (20) M indicates the maximum display width for INTEGER types. The maximum legal display width is 255.

11. Why try to have a primary key?

Primary keys ensure the uniqueness of data rows in the entire table. You are advised to add a self-growing ID column as the primary key even if the table does not have a primary key. After setting the primary key, it is possible to make subsequent deletions faster and ensure the safety of the operation data range.

13. If you want to store user password hashes, which fields should be used to store them?

Fixed length strings such as password hashes, salt, and user id numbers should be stored in char rather than vARCHar to save space and improve retrieval efficiency. ID;

(2). Select the correct storage engine.

(3). Use the smallest data type that can store data, integer < date,time < char,varchar < blob;

(4). Using simple data types, integer processing is less expensive than character processing because string comparisons are more complex. For example, int storage time type, bigint transfer IP function;

(5). Using reasonable field attribute lengths, fixed-length tables are faster. Use enum, char instead of varchar;

(6). Use not NULL to define fields whenever possible (set default values for empty fields);

(7) use text as little as possible;

(8). Establish appropriate indexes for frequently used and queried fields;

Finally:

Public number lu Java source code in order not to affect the viewing only selected two parts, the rest can be private I ebook to obtain.

Quality information sharing!