2011-07-22笔试题

来源:互联网 发布:effective java中文版 编辑:程序博客网 时间:2024/06/03 13:04

1.question:What do you understand by Synchronization?

Answer: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
E.g. Synchronizing a function:
public synchronized void Method1 () {
     // Appropriate method-related code. 
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
    synchronized (this) { 
            // Synchronized code here.
         }
}

2.question:What is Collection API?

Answer: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. 
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and
Map.

3.question:What do you know about GWT?

4.question:What is similarities/differecce between an Abstract class and Interface class?

Answer: Differences are as follows:

  Interfaces provide a form of multiple inheritance. A class can extend only one other class.

  Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.

  A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.

  Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. 

Similarities:

  Neither Abstract classes or Interface can be instantiated.

 中文:

        声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。Abstract 类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。

  接口(interface)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义static final成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,instanceof 运算符可以用来决定某对象的类是否实现了接口

 

5.question:How to convert String to Number in java program?

6.question:Explain garbage collection?

Answer: Garbage collection is one of the most important feature of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(),  JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. 

中文:

GC是垃圾收集器。Java 程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一:

System.gc()

Runtime.getRuntime().gc()

7.question:What are Access Specifiers available in java?

8.question:Read the following program:

         public class test{

                 public static void main(String[] args){

                    int x=3;

                    int y=1;

                    if(x=y)

                             System.out.println("Not equal");

                    else

                              System.out.println("Equal");

                   }

          }

       What is the result?

  Answer:Compile error 中文:编译错误

9.question:What is the base class for Error and Exception?

中文:

  error 表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。

  exception 表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。

10.question:What is the byte range?

11.question:How are memery leaks possibale in Java?

12.question:Describe the principles of OOPS?

Answer: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.    

中文:多态,继承,封装

13.question:Write a java function to calculate factorial.

           To remember factorial : 2!=2*1;3!=3*2*1;4!=4*3*2*1.

14.question:What is a scriptlet?

原创粉丝点击