Java面试

Questions
                                               Java面试问题
                              
Q: What is the difference between an Interface and an Abstract class?
问:接口与抽象类间的区别?
A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
A:抽象类可以有具体的实现方法,可以执行缺省行为,接口仅仅声明常量和实例      方法,但是不能执行缺省行为,并且所有方法隐含是抽象的。接口有所有公共成员但没有实现。抽象类是一个可以包括通常类成员(私有,保护,等)的类,但有一些抽象方法。
   
Q: What is the purpose of garbage collection in Java, and when is it used?  
问:在Java语言中垃圾回收机制的目的是什么,它用在什么时候?
A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.    A:垃圾回收机制的目的是为了识别和抛弃不再需要由程序控制的对象,从而实现资源的可再生和重用.如果一个对象没有在任何地方被引用,即没有任何一个引用指向这个对象,那么这个单元就是可以被回收的。

Q: Describe synchronization in respect to multithreading.
问:描述关于多线程的同步.
A: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.  
A:对于多线程, 同步是有能力控制出入的多线程共享资源。未经同步,有可能一个线程修改共享变量,而另一个线程在使用过程中或更新同一共享变量.这通常会导致重大的失误。

Q: Explain different way of using thread?
问:解释一下使用不同线程的方法?
A: The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.   
A:线程可以执行调用可运行接口或从线程类继承.前者是较为有利。起因是当你要作多重继承时.. 只有借助于接口。

Q: What are pass by reference and passby value?
问:什么是按参数传递和按值传递?
A: Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.      A:按参数传递意味着是通过地址本身来传递而不是通过值来传递,按值传递就是指将值拷贝进行传递

Q: What is HashMap and Map?
问:什么是HashMap和Map?
A: Map is Interface and Hashmap is class that implements that.
A:Map是接口而 HashMap是用来继承它的类。

Q: Difference between HashMap and HashTable?
问:Hashtable和HashMap的区别
A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.
A:HashMap类大致相当于HashTable,除了它不同步并且它允许一个 null 键和多个 null值(HashMap允许空值作为关键子和值,而HashTable不允许),随着时间的推移hashmap并不保证Map顺序保持不变,.HashMap不同步而HashTalue同步

Q: Difference between Vector and ArrayList?
问:Vector和ArrayList的区别?
A: Vector is synchronized whereas arraylist is not.
A:Vector同步但ArrayList不同步。

Q: Difference between Swing and Awt?
问:Swing和AWT的区别是什么?
A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT A:AWT是重量级组件,Swing是轻量级组件,因此Swing比AWT运行的更快。
   
Q: What is the difference between a constructor and a method?  
问:构造器和方法的区别:
A: A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.  A:构造器是被用来创建类对象的一个Function成员,它和类本身名字一样,没有返回类型,并且请求调用新的运算符。方法是类的一个普通Function成员,它有自己的名字,有返回类型(有可能是无效的),并且请求调用点运算符。

Q: What is an Iterator?
问:什么是迭代器?
A: Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator. A:一些集合类通过java.util.iterator接口提供他们的目录遍历.这个接口允许你通过对象集反过来走访每一个对象,记住当使用包含了一集合的快照的迭代器那时Iterators被获得; 当遍历Iterator时它一般不适合修改集合本身。
 
Q: State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers. 
问:独一陈述一下公共类(public),私有类(private),保护类(protected),缺省(default)修饰符的有效性,并结合这些修饰符陈述一下在声明项目条件时包关系间的作用?
A: public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.
A:public:public类可以供其他包中的类访问,在任何一处都可以访问到它的域(类也必须是public类)
private:私有变量或方法只能在声明了这个变量或方法的本类的实例中调用,私有属性只能通过拥有和它一样属性的类才能访问。
protected:在同样的包中供所有的类使用并且也供那些拥有Protected属性的类的所有子类使用,这个访问提供给属于在另外一个拥有Protected属性的包的子类
default:你通过缺省ie得到的,没有进行过任何访问修改的(ie,public,private或者protected).这意味它可以在所有特殊的包内访问到。

Q: What is an abstract class?
问:什么是一个抽象类?
A: Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.
A:抽象类必须是extended/subclassed(是有用的)。它相当于模板。抽象的类不能被实例化(ie,您不可以告诉它的建设者),抽象类可以包含静态数据。任一类以一个抽象方法自动地是抽象的本身,且必须被声明,一个类可以被声明是抽象的既使它没有抽象方法。这防止它被实例化。

Q: What is static in java?
问:在JAVA中static的意思是什么?
A: Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.
A:Static指代每一个类,而不是每一个对象,无论有多少类的实例可能存在.就是指你可以不用创建一个实例类就可以用他们。Static方法隐含了final,因为基于对象类型的重要性,并且Static方法不符于类,没有对象,一个Static方法在父类(superclass)中可能由其他Static方法隐含在子类中,只要原先的方法没有被声明final类,但是你不能忽略一个静态方法以一个nonstatic出现,换句话说,在子类中你无法改变一个静态方法到一个事例方法。

Q: What is final?
问:什么是final类?
A: A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).
A:final类不能被ie继承.,final类不可以被子类继承。final方法在当它的类被继承时不能重载,你不能改变final变量的值 (是一个恒值)。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值