1
、作用域
public,private,protected,
以及不写时的区别
答:区别如下:
作用域 当前类 同一 package 子孙类 其他 package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不写时默认为 friendly
2 、 ArrayList 和 Vector 的区别 ,HashMap 和 Hashtable 的区别
答:就 ArrayList 与 Vector 主要从二方面来说 .
一 . 同步性 :Vector 是线程安全的,也就是说是同步的,而 ArrayList 是线程序不安全的,不是同步的
二 . 数据增长 : 当需要增长时 ,Vector 默认增长为原来一培,而 ArrayList 却是原来的一半
就 HashMap 与 HashTable 主要从三方面来说。
一 . 历史原因 :Hashtable 是基于陈旧的 Dictionary 类的, HashMap 是 Java 1.2 引进的 Map 接口的一个实现
二 . 同步性 :Hashtable 是线程安全的,也就是说是同步的,而 HashMap 是线程序不安全的,不是同步的
三 . 值:只有 HashMap 可以让你将空值作为一个表的条目的 key 或 value
3 、 char 型变量中能不能存贮一个中文汉字 ? 为什么 ?
答:是能够定义成为一个中文的,因为 java 中以 unicode 编码,一个 char 占 16 个字节,所以放一个中文是没问题的
4 、多线程有几种实现方法 , 都是什么 ? 同步有几种实现方法 , 都是什么 ?
答:多线程有两种实现方法,分别是继承 Thread 类与实现 Runnable 接口
同步的实现方面有两种,分别是 synchronized,wait 与 notify
5 、继承时候类的执行顺序问题 , 一般都是选择题 , 问你将会打印出什么 ?
答 : 如下: 父类:
package
test;
public
class
FatherClass
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public FatherClass()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.out.println("FatherClass Create");
}
}
子类:
package
test;
import
test.FatherClass;
public
class
ChildClass
extends
FatherClass
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public ChildClass()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.out.println("ChildClass Create");
}
public static void main(String[] args)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
输出结果:
C:\>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
6、内部类的实现方式?
答:示例代码如下:
package
test;
public
class
OuterClass
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
private class InterClass
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public InterClass()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.out.println("InterClass Create");
}
}
public OuterClass()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InterClass ic = new InterClass();
System.out.println("OuterClass Create");
}
public static void main(String[] args)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
OuterClass oc = new OuterClass();
}
}
输出结果:
C:\>java test/OuterClass
InterClass Create
OuterClass Create
7 、 float 型 float f=3.4 是否正确 ?
答 : 不正确。精度不准确 , 应该用强制类型转换,如下所示: float f=(float)3.4
8 、介绍 JAVA 中的 Collection FrameWork( 包括如何写自己的数据结构 )?
答: Collection FrameWork 如下:
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
9、抽象类与接口?
答:抽象类与接口都用于抽象,但是抽象类(JAVA中)可以有自己的部分实现,而接口则完全是一个标识(同时有多重继承的功能)。
10、Java 的通信编程,编程题(或问答),用JAVA SOCKET编程,读服务器几个字符,再写入本地显示?
答:Server端程序:
package
test;
import
java.net.
*
;
import
java.io.
*
;
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
public
class
Server
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
private ServerSocket ss;
private Socket socket;
private BufferedReader in;
private PrintWriter out;
public Server()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ss=new ServerSocket(10000);
while(true)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
socket = ss.accept();
String RemoteIP = socket.getInetAddress().getHostAddress();
String RemotePort = ":"+socket.getLocalPort();
System.out.println("A client come in!IP:"+RemoteIP+RemotePort);
in = new BufferedReader(new
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
InputStreamReader(socket.getInputStream()));
String line = in.readLine();
System.out.println("Cleint send is :" + line);
out = new PrintWriter(socket.getOutputStream(),true);
out.println("Your Message Received!");
out.close();
in.close();
socket.close();
}
}catch (IOException e)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
out.println("wrong");
}
}
public static void main(String[] args)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
new Server();
}
}
;
Client
端程序
:
package
test;
import
java.io.
*
;
import
java.net.
*
;
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
public
class
Client
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
Socket socket;
BufferedReader in;
PrintWriter out;
public Client()
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.out.println("Try to Connect to 127.0.0.1:10000");
socket = new Socket("127.0.0.1",10000);
System.out.println("The Server Connected!");
System.out.println("Please enter some Character:"
答:区别如下:
作用域 当前类 同一 package 子孙类 其他 package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不写时默认为 friendly
2 、 ArrayList 和 Vector 的区别 ,HashMap 和 Hashtable 的区别
答:就 ArrayList 与 Vector 主要从二方面来说 .
一 . 同步性 :Vector 是线程安全的,也就是说是同步的,而 ArrayList 是线程序不安全的,不是同步的
二 . 数据增长 : 当需要增长时 ,Vector 默认增长为原来一培,而 ArrayList 却是原来的一半
就 HashMap 与 HashTable 主要从三方面来说。
一 . 历史原因 :Hashtable 是基于陈旧的 Dictionary 类的, HashMap 是 Java 1.2 引进的 Map 接口的一个实现
二 . 同步性 :Hashtable 是线程安全的,也就是说是同步的,而 HashMap 是线程序不安全的,不是同步的
三 . 值:只有 HashMap 可以让你将空值作为一个表的条目的 key 或 value
3 、 char 型变量中能不能存贮一个中文汉字 ? 为什么 ?
答:是能够定义成为一个中文的,因为 java 中以 unicode 编码,一个 char 占 16 个字节,所以放一个中文是没问题的
4 、多线程有几种实现方法 , 都是什么 ? 同步有几种实现方法 , 都是什么 ?
答:多线程有两种实现方法,分别是继承 Thread 类与实现 Runnable 接口
同步的实现方面有两种,分别是 synchronized,wait 与 notify
5 、继承时候类的执行顺序问题 , 一般都是选择题 , 问你将会打印出什么 ?
答 : 如下: 父类:
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
C:\>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
6、内部类的实现方式?
答:示例代码如下:
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
C:\>java test/OuterClass
InterClass Create
OuterClass Create
7 、 float 型 float f=3.4 是否正确 ?
答 : 不正确。精度不准确 , 应该用强制类型转换,如下所示: float f=(float)3.4
8 、介绍 JAVA 中的 Collection FrameWork( 包括如何写自己的数据结构 )?
答: Collection FrameWork 如下:
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
9、抽象类与接口?
答:抽象类与接口都用于抽象,但是抽象类(JAVA中)可以有自己的部分实现,而接口则完全是一个标识(同时有多重继承的功能)。
10、Java 的通信编程,编程题(或问答),用JAVA SOCKET编程,读服务器几个字符,再写入本地显示?
答:Server端程序:
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/None.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://hepeng1688.iteye.com/Images/OutliningIndicators/InBlock.gif)