Java面试问题 001-010

本文解答了Java面试中常见的问题,包括接口与抽象类的区别、垃圾收集的目的、多线程同步机制、线程的不同使用方式、传引用与传值的区别、HashMap与Map的概念及区别、HashMap与HashTable的区别、Vector与ArrayList的区别、Swing与AWT的区别以及构造函数与方法的区别。

 

原文来自http://www.allapplabs.com/interview_questions/java_interview_questions.htm

翻译:Zeng Yuetian

转载请注明出处。

 

 

 

Q001:

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.
抽象类可以有实现了默认行为的实例方法,接口只能声明常量和实例方法,但是不能实现默认的行为,并且所有的方法隐式地声明为abstract.

接口的所有成员都是public的,而且没有实现。一个抽象类拥有常见类成员的类(private, protected),只是它有一些abstract的方法.

 

Q002:

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.
垃圾收集的目的是识别和丢弃那些不会再为程序所用的对象,从而使得它们占用的资源可以被回收和重新使用。当java对象变得无法被使用它的程序到达时,将会进行垃圾收集。

 

Q003:

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. 
关于多线程,同步是控制多个线程访问共享资源的机制。没有同步,就会出现当一个线程修改共享变量的同时有其他线程使用和修改同一个共享变量。这通常会导致严重的错误。

 

Q004:

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.
线程可以通过runnable接口来实现,或者继承Thread类来实现。前者有更多的优点,因为当你准备实现多继承的时候,只有接口可以帮助你。

 

Q005:

What are pass by reference and pass by value?
什么是传引用和传值?

A:

Pass By Reference means the passing the address itself rather than passing the value. Pass by Value means passing a copy of the value to be passed. 
传引用意味着传递地址,传值意味着传递一份值的拷贝。

 

Q006:

What is HashMap and Map?
什么是HashMapMap

A:

Map is Interface and Hashmap is class that implements that.
Map
是接口,HashMap是实现了该接口的类。

 

Q007:

Difference between HashMap and HashTable?
HashMap
HashTable之间的区别是?

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.
HashMap
类基本上等同于HashTable,除了HashMap是非同步的并且允许包含null的(HashMap允许null值作为key和value,但是HashTable不允许)。HashMap并不保证一段时间后map的顺序恒定不变。HashMap是非同步的,HashMap是同步的。

 

Q008:

Difference between Vector and ArrayList?
Vector
ArrayList的区别是?

A:

Vector is synchronized whereas arraylist is not.
Vector
是同步的,ArrayList是非同步的。

 

Q009:

Difference between Swing and Awt?
Swing
Awt的区别是?

A:

AWT are heavy-weight components. Swings are light-weight components. Hence swing works faster than AWT.
AWT
是重量级的组件,而Swing是轻量级的组件。因此,SwingAWT速度要快。

 

Q010:

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.
构造函数是用来创建该类对象的成员函数。它和类拥有同样的名字,没有返回类型,用new操作符调用。
方法是类的普通成员函数。它有自己的名字,返回类型(可以为void),它用.操作符调用。

 

 

转载于:https://www.cnblogs.com/yuetiantian/archive/2010/01/26/1657008.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值