IBM interview experience

Source: Internet
Author: User

The last Microsoft interview experience was accidentally followed and discussed by many friends. I am grateful again. Although Microsoft was still defeated last time, it has also gained a lot. Many discussions and reflections outside of the interview, "perfect" is the most rewarding thing I have ever gained. I have discussed it with you last time. I am fortunate to have participated in the IBM interview recently. I hope to discuss it with you and give you some reflection and reference. The most important thing we have gained this time is the "meaning ".

IBM itself is not a well-developed company, but a company that pays more attention to its personal background. The company doesn't care how proficient a language is, how familiar a technology is, and what the company values is your comprehensive knowledge and foundation. Personality is on the one hand, IBM is more concerned with the basis of personal knowledge, especially for a small undergraduate (in fact, in the last month after a variety of written examination interviews, coupled with fighting in a remote location, the body has a feeling of virtual detachment. I really want to wait for a while and have a good rest ). The following lists the questions raised by the two interviewers during my interview today. I have made some special questions and answers to facilitate future review and review of the basic knowledge. In fact, some of the listed questions are only the first questions asked during the interview. Further discussions are not listed for a long time.

(1) Java object-oriented features are distinguished by rewriting and overloading.

Encapsulation, inheritance, polymorphism, abstraction

1. The concept of rewriting is generated in inheritance. If the subclass has the same function declaration as the parent class, the function is overwritten, And the subclass object cannot access this function in the parent class.

2. Overload means that several functions have similar function declarations. The parameter list is different, but the function is similar.


(2) concepts of Java containers. The difference between the arraylist and arraylist.

The Java container class includes list, arraylist, vector, MAP, hashtable, and hashmap.


(3) differences between hashmap and hashtable.Two underlying implementation methods of hash.

1. hashmap

1) Data Structure of hashmap

Hashmap is a combination of arrays and linked lists (called "linked list hash" in the data structure), as shown in:

When we put an element in a hashmap, we first calculate the hash value of the Key to the position (subscript) of the element in the array ), then you can put this element in the corresponding position. If the seat where this element is located already contains other elements, the elements in the same position will be stored in the form of a linked list, and the newly added elements will be placed in the chain head, the first join is placed at the end of the chain.

2) Use

Map map = new hashmap ();

Map. Put ("Fig", "100 ");

Map. Put ("rajibsarma", "200"); // the value "100" is replaced by "200 ".

Map. Put ("sazidahmed", "200 ");

 

Iteratoriter = map. entryset (). iterator ();

While (ITER. hasnext ()){

Map. Entry entry = (Map. Entry) ITER. Next ();

Object key = entry. getkey ();

Object val = entry. getvalue ();

}

2. Differences between hashtable and hashmap

First, inheritance is different.

Public classhashtable extends dictionary implements Map

Public classhashmap extends actmap implementsmap

Second

Methods In hashtable are synchronized, while those in hashmap are not synchronized by default. Hashtable can be used directly in a multi-thread concurrent environment, but you need to add synchronization to use hashmap.

Third

In hashtable, keys and values cannot contain null values.

In hashmap, null can be used as a key. Such a key has only one; one or more keys can correspond to null values. When the get () method returns a null value, it can indicate that the key does not exist in hashmap or that the corresponding value of the key is null. Therefore, the get () method cannot be used to determine whether a key exists in the hashmap. Instead, the containskey () method should be used to determine whether a key exists in the hashmap.

Fourth, the internal implementation of the two traversal methods is different.

Hashtable and hashmap both use iterator. For historical reasons, hashtable also uses the enumeration method.

Fifth

The hashcode of an object is directly used by hashtable. Hashmap recalculates the hash value.

Sixth

Hashtable and hashmap are two internal implementation methods: the initial size of the array and the method of resizing. In hashtable, the default size of the hash array is 11, and the increment is old * 2 + 1. The default size of the hash array in hashmap is 16, and it must be an index of 2.


(4) Whether the string in Java can be inherited


No. String is final and cannot be inherited.
Classes of basic types are all final classes and cannot be inherited or modified, such as integer, float, Boolean, byte, character, long, and short.

(5) differences between abstract classes and interfaces.

1. abstract classes can contain non-abstract methods.

However, the interface can only have abstract methods.

The class that declares the existence of a method without implementing it is called abstract class. It is used to create a class that reflects some basic behaviors and declare a method for this class, however, this class cannot be implemented in this class. You cannot create an abstract instance. However, you can create a variable whose type is a image class and point it to an instance of a specific subclass. There cannot be a pumping constructor or a pumping static method. The subclasses of abstract classes provide implementation for all the image extraction methods in their parent classes. Otherwise, they are also called image classes. Instead, implement this method in the subclass. Other classes that know their behavior can implement these methods in the class.

 

2. The interface is a variant of the image class. In the interface, all methods are extracted. Multi-inheritance can be achieved by implementing such an interface. All methods in the interface are drawn, and none of them has a program body. The interface can only define static final member variables. The implementation of an interface is similar to that of a subclass, except that the implementation class cannot inherit behaviors from the interface definition. When a class implements a special interface, it defines (to be given by the program body) all the methods of this interface. Then, it can call the interface method on any object of the class that implements this interface. Because of the image class, it allows the interface name to be used as the type of the referenced variable. Normally, dynamic Association editing will take effect. The reference can be converted to the interface type or from the interface type conversion, instanceof
The operator can be used to determine whether an object's class implements an interface.


(6) Java multithreading implementation methods.

There are also minor differences between the two methods of Java multithreading!

Inherit Thread class

Implement the runnable interface (note: the runnable interface is implemented when data is shared, which is not supported by the Thread class)

 

Threadt1 = new thread ()

{

Public void run ()

{

System. Out. println ("method 1 ");

}

};

T1.start ();

 

Threadt2 = new thread (New runnable ()

{

Public voidrun ()

{

System. Out. println ("method 2, which can achieve data sharing among similar Threads ");

}

});

T2.start ();

 

(7) differences between threads and processes and benefits of processes.

In short, a program has at least one process, and a process has at least one thread.

The thread division scale is smaller than the process, making the multi-thread program highly concurrent.
In addition, the process has independent memory units during execution, and multiple threads share the memory, which greatly improves the program running efficiency.
The execution process of a thread is different from that of a process. Each Independent thread has a program running entry, sequence execution sequence, and program exit. But the thread cannot be executed independently. It must exist in the application and the application provides multiple thread execution control.
Logically, multithreading means that multiple execution parts in an application can be executed simultaneously. However, the operating system does not view multiple threads as multiple independent applications to implement process scheduling, management, and resource allocation. This is an important difference between processes and threads.

A process is a running activity of a program with certain independent functions. A process is an independent unit for the system to allocate and schedule resources.
A thread is an entity of a process. It is the basic unit for CPU scheduling and scheduling. It is smaller than a process and can run independently. the thread itself basically does not have system resources, and only has a few resources (such as program counters, a set of registers and stacks) that are essential for running ), however, it can share all resources of a process with other threads of the same process.
One thread can create and cancel another thread, and multiple threads in the same process can be concurrently executed.

The main difference between processes and threads is that they are different operating system resource management methods. A process has an independent address space. After a process crashes, it will not affect other processes in the protection mode, but the thread is only a different execution path in the process. A thread has its own stack and local variables, but there is no separate address space between threads. If a thread dies, the whole process dies. Therefore, multi-process programs are more robust than multi-threaded programs, however, during process switching, resources are consumed and the efficiency is lower. But for some concurrent operations that require simultaneous and shared variables, you can only use threads, not processes.

(Note: The student ID has just pointed out a problem. The original words are as follows:

Most of the time, one field is blocked and other threads can continue running.
If a program does not need to use multiple processes, it will not be used. Not robust, but performance
If your thread does not affect the data in the critical section
It will not affect other threads.
Because it is parallel

)


(8) How does a 32-bit machine work.


(9)The difference between virtual memory and memory.


(10) Whether fast sorting is stable or not. What is stable.

1. Stable sorting

Bubble sort-O (n2)

Cocktail sorting (cocktail sort, bidirectional bubble sorting)-O (n2)

Insertion Sort-O (n2)

Bucket sort-O (n); requires O (k) Additional memory

Counting sort-O (N + k); requires O (N + k) Additional memory

Merge sort-O (n log n); requires O (n) Additional memory

Sort by in-situ merging-O (n2)

Binary Tree sorting (Binary treesort)-O (n log n); requires O (n) Additional memory

Base sorting (Radix sort)-O (n · K); requires O (n) Additional memory

2. Unstable sorting

Selection sort-O (n2)

Shell sort-O (n log n) if you use the best current version

Heapsort-O (n log n)

Quicksort-O (n log n) expected time, O (n2) Worst case; for large, random string columns, it is generally believed to be the fastest known sorting.

See: http://fei-cool.blog.sohu.com/152000311.html


(11)KMP search


(12) Implementation of the red and black trees


(13) Design Model

There are three types of design patterns: creation, structure, and behavior. Among them, the creation type is: 1. Singleton. Singleton mode: ensure that a class has only one instance, and provide a global access point to it. 2. Abstract Factory, Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes. 3. Factory method: Define an interface used to create objects, and let the subclass decide which class to instantiate. Factory method delays the instantiation of a class to the subclass. 4. Builder: separates the construction of a complex object from its representation, so that different representations can be created during the same construction process. 5. prototype: Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object. Behavior types: 6. iterator. iterator mode: provides a method to access each element of an aggregate object sequentially without exposing the internal representation of the object. 7. Observer: Observer mode: defines one-to-many dependencies between objects. When the status of an object changes, all objects dependent on it will be automatically updated by notification. 8. template method: defines the skeleton of an algorithm in an operation, and delays some steps to the subclass, templatemethod allows the subclass to redefine a specific step without changing the structure of an algorithm. 9. Command: encapsulate a request as an object so that you can parameterize the customer with different requests, queue requests and record request logs, and supports unrecoverable operations. 10. State: allows an object to change its behavior when its internal state changes. The object seems to have changed its class. 11. Strategy: Define a series of algorithms, encapsulate them one by one, and enable them to replace each other. This mode allows algorithms to be independent of customers who use them. 12. China of responsibility, responsibility chain mode: Enables multiple objects to process requests, so as to avoid coupling between the request sender and receiver. 13. mediator. intermediary mode: encapsulate object interaction of some columns with an intermediary object. 14. Visitor, visitor mode: indicates an operation that acts on each element in an object structure. It allows you to define new operations that act on this element without changing the element classes. 15th, interpreter, interpreter mode: a language is defined to define a representation of its grammar and an interpreter. This interpreter uses this representation to explain sentences in the language. 16. Memento: capture the internal state of an object without interrupting the object, and save the state outside the object. Structural types include: 17 and composite. Combination Mode: the object is combined into a tree structure to represent the relationship between the whole part. Composite makes the use of a single object and the combination object consistent. 18. facade, appearance mode: provides a consistent interface for a group of interfaces in the subsystem. Fa? Ade provides a high-level interface, which makes the subsystem easier to use. 19. Proxy: provides a proxy for other objects to control access to this object. 20. Adapter. Adapter mode: the adapter mode converts a class-1 interface to another interface that the customer wants. The adapter mode makes those classes unable to work together due to incompatibility of the interface. 21. decrator: the decorator mode dynamically adds some additional responsibilities to an object. In terms of the added functions, the decorator mode is more flexible than the subclass generation mode. 22. Bridge: separates the abstract part from its implementation part so that they can change independently. Twenty-three, flyweight, metadata-Sharing Mode

(14) self-description in English, not self-introduction.


(You are welcome to leave a message to discuss and make progress together .)


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.