1经历了两次网上测试和两次电面,发现网上测试和电面题目都是不变的,电面题目相当固定,具体试题如下:
(当时精心准备了所有的电面试题,整理出了两个word文档,有很多图片辅助理解,现在将重要内容写到这里,图片就不贴上来了,有需要的可以回复)
电面分若干小题与一道设计大题,小题都是考一些小知识点,如面向对象编程基础,大题两次电面都是一个题目,会议室预定的数据库设计,每个表包含哪些属性等,比较基础
电面试题
1.Index
Data structure,stores the valueof specific colum in table,pointer to the row in table,allow for fasterretreaval of data in database,speed up search query.
Hash index,not orderd,compare for equalitybut not for inequality.
B-tree, allows logarithmic selections,insertions, and deletions in the worst case scenario. And unlike hash indexesit stores the data in an ordered way, allowing for faster row retrieval whenthe selection conditions include things like inequalities or prefixes.
2.stack vs heap
Stack:static;compile time;LIFO order;memorymanagement automatically;access fast;
Know how much data before compile,not toomuch;
Heap:dynamic;run time;slower;size Islimited on virtual memory;allocat and free at any time;
3.thread vs process
Thread:run in shared memory space;easier tocreate and terminate;lightweight;faster task-switching;data sharing with otherthread;care synchronization overhead of shared data;
Process:separate memory space;independentof each other;consist of mutipule thread
4.Garbage Collection (GC)
Mark:reffrence counting and reachability analysis;
Clean up:sweep(hace fragment,old),coping(no fragment,eden),compact(nofragment,difficult to concurrent)
Gennerational:(young:coping,old:mark-sweep/compact,permenant:class,const,staticvariable,method)
CMS: Initial Mark, Concurrent Mark, Remark, Concurrent Sweep
5. Interface Vs Abstract method
Abstract method:constants,members,methodstubs,defined method;any visibility;single class;chile class, with the same orless restrictive visibility
Interface:const,methodstubs;public;multipul interface;child interface,same visibility;
6.sql join
INNER JOIN: Returns all rows when there isat least one match in BOTH tables
LEFT JOIN: Return all rows from the lefttable, and the matched rows from the right table
RIGHT JOIN: Return all rows from the righttable, and the matched rows from the left table
FULL JOIN: Return all rows when there is amatch in ONE of the tables
7. virtual method and inheritance
Inheritance allows us to define a class in terms of another class, which makesit easier to create and maintain an application. This also provides anopportunity to reuse the code functionality and fast implementation time.
8. Primary key and foreign key
PK:duplicated values not allowed;notnull;only one in a table;
FK:duplicated;null;one or more in a table;
9. copy constructor and assignment operator
copy constructor :Initialize a previous un-initialized object with the data of otherexist object;
assignment operator: replace the data of a previously initialized object with some otherobject's data
10.pointer and reference
Pointer:1.can bere-assign many times;2.can point to null;3.has its own memory address and sizeon stack;4.can have pointer to pointers to pointers offering extra levels ofindirection
Reference;1.can’t bere-seated after binding;2.always refer to an object;3.share the same memoryspace with origin object;4.only one level indirection
11.polymorphsim
Polymorphism is when you can treat anobject as a generic version of something, but when you access it, the codedetermines which exact type it is and calls the associated code
polymorphism is the ability (in programming)to present the same interface for differing underlying forms (data types).
12. what is staticmethod?
A static method is amethod that can be called on a class and usually does not require the class tobe instantiated.
13.what's thedifference between TCP and UDP?
Reliability: TCP is connection-orientedprotocol.
Reliability: UDP is connectionlessprotocol.
Ordered: don’t have to worry about dataarriving in the wrong order.
Ordered: If you send two messages out, youdon’t know what order they’ll arrive in i.e. no ordered
Heavyweight:
Lightweight: No ordering of messages, notracking connections,
Streaming: Data is read as a “stream,” withnothing distinguishing where one packet ends and Datagrams: Packets are sentindividually and are guaranteed to be whole if they arrive. One packet
14. Smart pointer
A smart pointer is a class that wraps a'raw' (or 'bare') C++ pointer, to manage the lifetime of the object beingpointed to
Reference counted pointers are very usefulwhen the lifetime of your object is much more complicated, and is not tieddirectly to a particular section of code or to another object.
15.Exception and Error
Errors tend to signal the end of yourapplication as you know it. It typically cannot be recovered from and shouldcause your VM to exit. Catching them should not be done except to possibly logor display and appropriate message before exiting.
Example: OutOfMemoryError - Not much you can do as your program can no longer run.
Exceptions are often recoverable and evenwhen not, they generally just mean an attempted operation failed, but yourprogram can still carry on.
Example: IllegalArgumentException - Passed invalid data to a method so that method call failed, but itdoes not affect future operations.
16. Sleep() VS wait()
Sleep:Thread类的静态方法,虽然休眠,但是锁并未释放,是当前线程进入停滞状态,让出cpu
Wait:object类的方法,进入等待池中,释放对象的锁;使用notify或notify all 唤醒等待池中的线程。Wait必须放在synchronize Blocking中,否则runtime 抛出illegalMonitorStateException。
17.C++ vs C
1C is a structural or proceduralprogramming language.
C++ is an object oriented programminglanguage.
2Functions are the fundamental buildingblocks.
Objects are the fundamental buildingblocks.
3In C, the data is not secured.
Data is hidden and can’t be accessed byexternal functions.
4C uses scanf() and printf() function forstandard input and output.
C++ uses cin>> and cout<< forstandard input and output.
5. C doesn’t support exception handlingdirectly. Can be done by using some other functions.
C++ supports exception handling. Done byusing try and catch block.
6. Features like function overloading andoperator overloading is not present.
C++ supports function overloading andoperator overloading.
18. diffrence between Java and C++
Garbage collection/delete
1.Everything must be in a class. There areno global functions or global data. If you want the equivalent of globals, makestatic methods andstatic data within a class. There are no structs orenumerations or unions, only classes.
2.Write once, run anywhere, but it's stillmuch easier than writing a C++ cross-platform code.
3.C++ supports multiple class inheritance,while Java only gives you a single class inheritance, but solves themultiplicity via interfaces.
4.C++ has got a pointers, and can directlymanipulate/violate the memory addresses.
5.At compilation time Java Source codeconverts into byte code .The interpreter execute this byte code at run time andgives output .Java is interpreted for the most part and hence platformindependent. C++ run and compile using compiler which converts source code intomachine level languages so c++ is plate from dependents
Java uses compiler and interpreter both andin c++ their is only compiler
C++ supports operator overloading multipleinheritance but java does not.
C++ is more nearer to hardware then Java
Everything (except fundamental types) is anobject in Java (Single root hierarchy as everything gets derived fromjava.lang.Object).
Java does is a similar to C++ but not haveall the complicated aspects of C++ (ex: Pointers, templates, unions, operatoroverloading, structures etc..) Java does not support conditional compile(#ifdef/#ifndef type).
Thread support is built-in Java but not inC++. C++11, the most recent iteration of the C++ programming language does haveThread support though.
Internet support is built-in Java but notin C++. However c++ has support for socket programming which can be used.
Java does not support header file, includelibrary files just like C++ .Java use import to include different Classes andmethods.
Java does not support default argumentslike C++.
There is no scope resolution operator :: inJava. It has . using which we can qualify classes with the namespace they camefrom.
There is no goto statement in Java.
Exception and Auto Garbage Collectorhandling in Java is different because there are no destructors into Java.
Java has method overloading, but nooperator overloading just like c++.
The String class does use the + and +=operators to concatenate strings and String expressions use automatic typeconversion,
Java is pass-by-value.
Java does not support unsigned integer
19.privateconstructor:
1. The constructor can only be accessedfrom static factory method inside the class itself.Singleton can also belong to this category.
2. A utility class, that only contains static methods.
Protected constructor
When a class is (intended as) an abstractclass, a protected constructor is exactly right. In that situation you don'twant objects to be instantiated from the class but only use it to inherit from.
There are other uses cases, like when acertain set of construction parameters should be limited to derived classes.
20.sql注入injection
submit a database SQL command that is executed by a webapplication,exposing the back-end database. A SQL injection attack can occurwhen a web applicationutilizes user-supplied data without proper validation orencoding as part of a command or query.
· when data entered by users issent to the SQL interpreter as a part of a SQL query.
· Attackers provide speciallycrafted input data to the SQL interpreter and trick the interpreter to executeunintended commands.
· A SQL injection attack exploitssecurity vulnerabilities at the database layer. By exploiting the SQL injectionflaw, attackers can create, read, modify or delete sensitive data.
Preventing SQL Injection
· Youcan prevent SQL injection if you adopt aninput validation technique in which user input isauthenticated against a set of defined rules for length, type and syntax and also against businessrules.
Youshould ensure that userswith the permission to access the database have the least privileges.
· Usestrongly typed parameterized query APIs with placeholder substitution markers, even when calling storedprocedures.
21.Multithread designpattern(多线程设计模式)
Single Threaded Execution: 只允许单个线程执行对象的某个方法,以保护对象的多个状态。
实现时需用synchronized修饰引用受保护的状态的方法,这样就只能有单个线程访问该方法,其它线程由于不能获取锁而等待。但是用synchronized保护变量也带来了性能问题,因为获取锁需要时间,并且如果多个线程竞争锁的话,会让某些线程进入这个锁的条件队列,暂停执行,这样会降低性能。
Immutable: 如果状态根本不会发生变化,就不需要用锁保护,这就是Immutable模式。
Person类用final修饰,防止被继承。_name和_address都用final修饰,防止被修改,只能在定义时初始化,或者在构造器里初始化,Person类也只提供了对这些状态字段的get方法,
Guarded Suspension:
当我们调用对象某个的某个方法时,可能对象当前状态并不满足执行的条件,于是需要等待,这就是GuardedSuspension模式。只有当警戒条件满足时,才执行,否则等待,另外对象必须有改变其状态的方法。
Balking: Balking模式与Guarded Suspension模式相似,都是在对象状态不符合要求时需要进行一些处理,不过Guared Suspension在状态不满足要求时,会等待并阻塞线程,而Balking模式是直接返回,并不等待。调用者可暂时先做别的工作,稍后再来调用该对象的方法。
不想等待警戒条件成立时,适合使用Balking模式。
警戒条件只有第一次成立时,适合使用Balking模式。
Producer-Consumer: 在该模式里可能有多个生产者,多个消费者,生产者和消费者都有独立的线程。其中最关键的是放置数据的缓冲区,生产者和消费者在操作缓冲区时都必须同步,生产者往缓冲区放置数据时,如果发现缓冲区已满则等待,消费者从缓冲区取数据时如果发现缓冲区没有数据,也必须等待。当程序里有多个生产者角色或者多个消费者角色操作同一个共享数据时,适合用生产者消费者模式。比如下载模块,通常会有多个下载任务线程(消费者角色),用户点击下载按钮时产生下载任务(生产者角色),它们会共享任务队列。
Read-WriteLock: 先前的几个多线程设计模式里,操作共享数据时,不管如何操作数据一律采取互斥的策略(除了Immutable模式),即只允许一个线程执行同步方法,其它线程在共享数据的条件队列里等待,只有执行同步方法的线程执行完同步方法后被阻塞的线程才可在获得同步锁后继续执行。
这样效率其实有点低,因为读操作和读操作之间并不需要互斥,两个读线程可以同时操作共享数据,读线程和写线程同时操作共享数据会有冲突,两个写线程同时操作数据也会有冲突。
Deadlock
Mutualexclusion - Each resource is either currentlyallocated to exactly one process or it is available. (Two processes cannotsimultaneously control the same resource or be in their critical section).
Holdand Wait - processes currently holding resourcescan request new resources.
Nopreemption - Once a process holds a resource, itcannot be taken away by another process or the kernel.
Circularwait - Each process is waiting to obtain a resourcewhich is held by another process.
22.Desing pattern
FactoryMethod:
The Factory Method Pattern defines aninterface for creating an object, but lets subclasses decide which class toinstantiate. Factory Method lets a class defer instantiation to subclasses.
0. Programming
Index
Indexing is a way of sorting anumber of records on multiple fields. Creating an index on a field in a tablecreates another data structure which holds the field value, and pointer to therecord it relates to. This index structure is then sorted, allowing BinarySearches to be performed on it.
The downside to indexingis that these indexes require additional space on the disk,since the indexes are stored together in a table using the MyISAM engine, thisfile can quickly reach the size limits of the underlying file system if manyfields within the same table are indexed.
, the cardinality or uniqueness of the data isimportant.
With such a low cardinality the effectivenessis reduced to a linear sort, and the query optimizer will avoid using the indexif the cardinality is less than 30% of the record number, effectively makingthe index a waste of space.
1. Stack VS Heap
Stack :
Static memory allocation
Don’t need to Manage the memory by ourselves, variable canbe allocated automaticlly
Access fast
Space is effient used,not fragment
Heap:
Dynamic memory allocation
Must manage the memory,in charge of allocating and freeingthe variables,or it maybe lead to memory leak.
Access slow
Space is not edffient
GarbageCollection
http://www.cnblogs.com/zhguang/p/3257367.html
http://blog.csdn.net/u014536596/article/details/49824659
- 可以作为GC Roots的对象包括以下几类:
- 虚拟机栈中引用的对象
- 方法区中类静态属性引用的对象
- 方法区中常量引用的对象
- Native方法引用的对象
Clean Up
清理阶段。将Mark阶段标记出的不可用对象清除,释放其所占用的内存空间。主要有以下几种实现方式。
· 清除(Sweep)
算法思想:遍历堆空间,将Mark阶段标记不可用的对象清除。
不足:效率不高;空间问题,多次清除之后会产生大量的内存碎片。