面经

来源:互联网 发布:什么是好的相声知乎 编辑:程序博客网 时间:2024/05/01 02:52

本着分享的原则与大家交流一下我的经验:


1、首先是一个test,需要先填写自己对各方面知识的熟悉程度,例如数据库、语言、技术等等;然后需要完成一道编程题,本人的题目是寻找两个文件的相同元素之间的confict, extract元素。

     我采取的做法是首先把文件分开,形成字符串数组,然后利用下标来进行判断:未出现在另一个文件的元素flag置为-1,否则置为对应下标。最后只需要判断-1的元素属于哪个情况。而我们可以找到-1元素的最近上一个非-1元素和最近下一个非-1元素,如果相差为1,那么该-1元素是extract;否则是conflict。

    注:需要考虑一种情况,存在二义性。那么我们可以以第一个文件为标准,以后只从第二个文件出现的相同元素处往后搜索,而不会存在交替相同的情况。


2、做完后,拿着跟着第一个面试官,他主要考察该算法的思想和优化可能,以及可能出现的问题。

     被问到的有一些java基础问题:

     1.sortedlist 与 hashtable 哪个更高效,为什么?

     http://www.cnblogs.com/plin2008/archive/2009/05/05/1450201.html

     http://blog.csdn.net/totty2006/article/details/8988132

     http://blog.csdn.net/huzanqiang8/article/details/744275

     Hashtable 索引效率高,但是装箱拆箱很影响效率
     Dictionary 刚好相反
     一般集合内容的类型固定就用用Dictionary,涉及多种类型或未知类型就用Hashtable 
     SortedDictionary 一看Sorted就知道,新增和删除时都会对集合重新排序,所以效率会很低,但是索引效率高


     2.hashmap 和 hashtable 的区别。

     答:1 hashmap非同步,hashtable同步 2. hashmap可以存入null的key和value,hashtable不行  3. 他们俩继承不同的父类


     3.override 和 overwrite 的区别。   OOP三大特性:继承,多态,封装。

     答:override 重载:同名函数不同参数(个数、顺序、类型)具有不同实现。  overwrite 重写:子类重写父类的函数。

   重载(Overloading)

    (1) 方法重载是让类以统一的方式处理不同类型数据的一种手段。多个同名函数同时存在,具有不同的参数个数/类型。重载Overloading是一个类中多态性的一种表现。    

    (2) Java的方法重载,就是在类中可以创建多个方法,它们具有相同的名字,但具有不同的参数和不同的定义。

    (3) 重载的时候,方法名要一样,但是参数类型和个数不一样,返回值类型可以相同也可以不相同。无法以返回型别作为重载函数的区分标准。

 1、必须具有不同的参数列表;

 2、可以有不同的返回类型,只要参数列表不同就可以了;

 3、可以有不同的访问修饰符;

 4、可以抛出不同的异常

    重写(Overriding) 有时子类并不想原封不动地继承父类的方法,而是想作一定的修改,这就需要采用方法的重写。方法重写又称方法覆盖 

     (1) 父类与子类之间的多态性,对父类的函数进行重新定义。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding)。在Java中,子类可继承父类中的方法,而不需要重新编写相同的方法。  

     (2)若子类中的方法与父类中的某一方法具有相同的方法名、返回类型和参数表,则新方法将覆盖原有的方法。

     (3)子类函数的访问修饰权限不能少于父类的;重写方法只能存在于具有继承关系中,重写方法只能重写父类非私有的方法。如需父类中原有的方法,可使用super关键字,该关键字引用了当前类的父类。


1、参数列表必须完全与被重写的方法相同,否则不能称其为重写而是重载。

2、返回的类型必须一直与被重写的方法的返回类型相同,否则不能称其为重写而是重载。

3、访问修饰符的限制一定要大于被重写方法的访问修饰符(public>protected>default>private)

4、重写方法一定不能抛出新的检查异常或者比被重写方法申明更加宽泛的检查型异常。例如:父类的一个方法申明了一个检查异常IOException,在重写这个方法是就不能抛出Exception,只能抛出IOException的子类异常,可以抛出非检查异常。


     重写与重载的区别在于:

     重写多态性起作用,对调用被重载过的方法可以大大减少代码的输入量,同一个方法名只要往里面传递不同的参数就可以拥有不同的功能或返回值。

用好重写和重载可以设计一个结构清晰而简洁的类,可以说重写和重载在编写代码过程中的作用非同一般.


     4. polymorphism 

     答:我们老师说的以上两种均为多态,但本人认为overwrite是的,多态需要有继承、重写、动态绑定。

   the ability in computer programming to present the same interface for differing underlying forms (data types)

      使用继承性的结果就是可以创建一个类的家族,在认识这个类的家族时,就是把导出类的对象当作基类的对象,这种认识又叫作upcasting。这样认识的重要性在于:我们可以只针对基类写出一段程序,但它可以适应于这个类的家族,因为编译器会自动找出合适的对象来执行操作。这种现象又称为多态性。而实现多态性的手段又叫称动态绑定(dynamic binding)。

 

调用方法时通过传递给它们的不同参数个数和参数类型来决定具体使用哪个方法, 这就是多态性。

1. 同样的一个方法能够根据输入数据的不同,做出不同的处理,即方法的重载——有不同的参数列表(静态多态性)

2. 多态性是面向对象编程的一种特性,和方法无关,而当子类继承自父类的相同方法,输入数据一样,但要做出有别于父类的响应时,你就要覆盖父类方法, 即在子类中重写该方法——相同参数,不同实现(动态多态性)


     5. long string reverse without additional memory

     答:用stack,不用stack的话不知道。还有递归,循环,异或交换元素

     http://www.cnblogs.com/kirinboy/archive/2010/04/23/reverse-a-string.html

     http://haolloyin.blog.51cto.com/1177454/560597/


     6. software development life cycle

     答:曾经做过的大型软件设计就是按照瀑布模型来的,requirements --- plan --- basic design --- detailed design --- test --- maintain

     还叙述了其中所涉及的文档,包括周报、小组章程和各阶段文档、用户手册等等。 描述了其中遇到的问题,编程问题、组员管理问题。


    7. how can I adapt to heavy work-load environment?

    答: I’m also aggressive and hardworking, so it won't be a problem for me to work heavily. The experience in my high school was quite convincing that I have the capability to work hard and learn fast,


    8. singleton and static 

    答:class level and parameter level

GoF:

The Singleton pattern has several benefits:

1。Controlled access to sole instance. Because the Singleton class encapsulates its sole instance, it can have strict control over how and when clients access it. 

2。Reduced name space. The Singleton pattern is an improvement over global variables. It avoids polluting the name space with global variables that store sole instances. 

3。Permits refinement of operations and representation. The Singleton class may be subclassed, and it's easy to configure an application with an instance of this extended class. You can configure the application with an instance of the class you need at run-time. 

4。Permits a variable number of instances. The pattern makes it easy to change your mind and allow more than one instance of the Singleton class. Moreover, you can use the same approach to control the number of instances that the application uses. Only the operation that grants access to the Singleton instance needs to change. 

5。More flexible than class operations. Another way to package a singleton's functionality is to use class operations (that is, static member functions in C++ or class methods in Smalltalk). But both of these language techniques make it hard to change a design to allow more than one instance of a class. Moreover, static member functions in C++ are never virtual, so subclasses can't override them polymorphically. 
    

     http://forum.unity3d.com/threads/singleton-vs-static.197169/


3、休息一会,第二个面试官来咯

    1. give a short self-introduction:  aha.. I'm a little star with five angles and four words can describe myself.
    2. favorite technique :  java of course
    3. talk about object:  equals, hashCode, toString, finilize
    4. other technique : c#, c, python 
    5. difference between c# and java: GUI...

    http://tonylian.iteye.com/blog/401683

    http://www.25hoursaday.com/CsharpVsJava.html


    6. memory leak: vector still have reference to items in it
    7. deal with lazy people: wow... 
    8. find the missing number... O(n*logn)  O(1)

    sort...


4、summary

   I  should have learnt more about data structure and agrithem design.. also pick up some knowledge about database, network and software development.

0 0
原创粉丝点击