2011-07-22筆試題

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?

發佈了29 篇原創文章 · 獲贊 4 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章