java面试题及答案

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 、继承时候类的执行顺序问题 , 一般都是选择题 , 问你将会打印出什么 ?
答 : 如下: 父类:
None.gif package  test;
None.gif
public   class   FatherClass
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public FatherClass()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  System.out.println(
"FatherClass Create");
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
子类:
None.gif package  test;
None.gif
import  test.FatherClass;
None.gif
public   class   ChildClass  extends  FatherClass
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif 
public ChildClass()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  System.out.println(
"ChildClass Create");
ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args) 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  FatherClass fc 
= new FatherClass();
InBlock.gif  ChildClass cc 
= new ChildClass();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
输出结果:
C:\>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create

6、内部类的实现方式?
答:示例代码如下:
None.gif package  test;
None.gif
public   class   OuterClass
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif 
private class InterClass
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
public InterClass()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   System.out.println(
"InterClass Create");
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public OuterClass()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  InterClass ic 
= new InterClass();
InBlock.gif  System.out.println(
"OuterClass Create");
ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args) 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  OuterClass oc 
= new OuterClass();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

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)可以有自己的部分实现,而接口则完全是一个标识(同时有多重继承的功能)

10Java 的通信编程,编程题(或问答),用JAVA SOCKET编程,读服务器几个字符,再写入本地显示? 
:Server端程序:

None.gif package  test;
None.gif
import  java.net. * ;
None.gif
import  java.io. * ;
None.gif
None.gif
public   class  Server
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif 
private ServerSocket ss;
InBlock.gif 
private Socket socket;
InBlock.gif 
private BufferedReader in;
InBlock.gif 
private PrintWriter out;
InBlock.gif 
public Server()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
try
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   ss
=new ServerSocket(10000);
InBlock.gif   
while(true)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    socket 
= ss.accept();
InBlock.gif    String RemoteIP 
= socket.getInetAddress().getHostAddress();
InBlock.gif    String RemotePort 
= ":"+socket.getLocalPort();
InBlock.gif    System.out.println(
"A client come in!IP:"+RemoteIP+RemotePort);
InBlock.gif    in 
= new BufferedReader(new 
InBlock.gif
InBlock.gifInputStreamReader(socket.getInputStream()));
InBlock.gif    String line 
= in.readLine();
InBlock.gif    System.out.println(
"Cleint send is :" + line);
InBlock.gif    out 
= new PrintWriter(socket.getOutputStream(),true);
InBlock.gif    out.println(
"Your Message Received!");
InBlock.gif    out.close();
InBlock.gif    in.close();
InBlock.gif    socket.close();
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }
catch (IOException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   out.println(
"wrong");
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
new Server();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}
;
None.gif
Client 端程序 :
None.gif package  test;
None.gif
import  java.io. * ;
None.gif
import  java.net. * ;
None.gif
None.gif
public   class  Client
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif Socket socket;
InBlock.gif BufferedReader in;
InBlock.gif PrintWriter out;
InBlock.gif 
public Client()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
try
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   System.out.println(
"Try to Connect to 127.0.0.1:10000");
InBlock.gif   socket 
= new Socket("127.0.0.1",10000);
InBlock.gif   System.out.println(
"The Server Connected!");
InBlock.gif   System.out.println(
"Please enter some Character:");
InBlock.gif   BufferedReader line 
= new BufferedReader(new 
InBlock.gif
InBlock.gifInputStreamReader(System.in));
InBlock.gif   out 
= new PrintWriter(socket.getOutputStream(),true);
InBlock.gif   out.println(line.readLine());
InBlock.gif   in 
= new BufferedReader(new InputStreamReader(socket.getInputStream()));
InBlock.gif   System.out.println(in.readLine());
InBlock.gif   out.close();
InBlock.gif   in.close();
InBlock.gif   socket.close();
ExpandedSubBlockEnd.gif  }
catch(IOException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   out.println(
"Wrong");
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
new Client();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}
;
None.gif

11 、用 JAVA 实现一种排序, JAVA 类实现序列化的方法 ( 二种 )   如在 COLLECTION 框架中,实现比较要实现什么样的接口?
: 用插入法进行排序代码如下:
None.gif package  test;
None.gif
import  java.util. * ;
None.gif
class   InsertSort
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif ArrayList al;
InBlock.gif 
public InsertSort(int num,int mod)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  al 
= new ArrayList(num);
InBlock.gif  Random rand 
= new Random();
InBlock.gif  System.out.println(
"The ArrayList Sort Before:");
InBlock.gif  
for (int i=0;i<num ;i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   al.add(
new Integer(Math.abs(rand.nextInt()) % mod + 1));
InBlock.gif   System.out.println(
"al["+i+"]="+al.get(i));
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public void SortIt()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  Integer tempInt;
InBlock.gif  
int MaxSize=1;
InBlock.gif  
for(int i=1;i<al.size();i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif       tempInt 
= (Integer)al.remove(i);
InBlock.gif    
if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     al.add(MaxSize,tempInt);
InBlock.gif     MaxSize
++;
InBlock.gif     System.out.println(al.toString());
ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif     
for (int j=0;j<MaxSize ;j++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      
if 
InBlock.gif
InBlock.gif(((Integer)al.get(j)).intValue()
>=tempInt.intValue())
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif       al.add(j,tempInt);
InBlock.gif       MaxSize
++;
InBlock.gif       System.out.println(al.toString());
InBlock.gif       
break;
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif  }

InBlock.gif  System.out.println(
"The ArrayList Sort After:");
InBlock.gif  
for(int i=0;i<al.size();i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   System.out.println(
"al["+i+"]="+al.get(i));
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args) 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  InsertSort is 
= new InsertSort(10,100);
InBlock.gif  is.SortIt();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
JAVA 类实现序例化的方法是实现 java.io.Serializable 接口
Collection
框架中实现比较要实现 Comparable  接口和  Comparator  接口

12 、编程:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。   但是要保证汉字不被截半个,如 ABC”4 ,应该截为 AB” ,输入 ABC DEF” 6 ,应该输出为 ABC” 而不是 ABC+ 汉的半个  
答:代码如下:
None.gif package  test;
None.gif
None.gif
class   SplitString
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif String SplitStr;
InBlock.gif 
int SplitByte;
InBlock.gif 
public SplitString(String str,int bytes)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  SplitStr
=str;
InBlock.gif  SplitByte
=bytes;
InBlock.gif  System.out.println(
"The String is:'"+SplitStr+"';SplitBytes="+SplitByte);
ExpandedSubBlockEnd.gif }

InBlock.gif 
public void SplitIt()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
int loopCount;
InBlock.gif  
InBlock.gif
InBlock.gifloopCount
=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/Split
InBlock.gif
InBlock.gifByte
+1);
InBlock.gif  System.out.println(
"Will Split into "+loopCount);
InBlock.gif  
for (int i=1;i<=loopCount ;i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
if (i==loopCount)dot.gif{
InBlock.gif    
InBlock.gif
InBlock.gifSystem.out.println(SplitStr.substring((i
-1)*SplitByte,SplitStr.length()));
ExpandedSubBlockStart.gifContractedSubBlock.gif   }
 else dot.gif{
InBlock.gif    
InBlock.gif
InBlock.gifSystem.out.println(SplitStr.substring((i
-1)*SplitByte,(i*SplitByte)));
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args) 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  SplitString ss 
= new SplitString("test中dd文dsaf中男大3443n中国43中国人
InBlock.gif

InBlock.gif0ewldfls
=103",4);
InBlock.gif
  ss.SplitIt();
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif

13 STRING STRINGBUFFER 的区别。  
答: STRING 的长度是不可变的, STRINGBUFFER 的长度是可变的。如果你对字符串中的内容经常进行操作,特别是内容要修改时,那么使用 StringBuffer ,如果最后需要 String ,那么使用 StringBuffer toString() 方法

Jsp方面

1
jsp有哪些内置对象?作用分别是什么?
:JSP共有以下9种基本内置组件(可与ASP6种内部组件相对应): 
 request 用户端请求,此请求会包含来自GET/POST请求的参数 
   response 
网页传回用户端的回应 
   pageContext 
网页的属性是在这里管理 
   session 
与请求有关的会话期 
   application servlet 
正在执行的内容 
   out 
用来传送回应的输出
   config servlet
的构架部件 
   page JSP
网页本身 
   exception 
针对错误网页,未捕捉的例外 

2
jsp有哪些动作?作用分别是什么?
:JSP共有以下6种基本动作
   jsp:include
:在页面被请求的时候引入一个文件。 
   jsp:useBean
:寻找或者实例化一个JavaBean 
   jsp:setProperty
:设置JavaBean的属性。 
   jsp:getProperty
:输出某个JavaBean的属性。 
   jsp:forward
:把请求转到一个新的页面。 
   jsp:plugin
:根据浏览器类型为Java插件生成OBJECTEMBED标记

3
JSP中动态INCLUDE与静态INCLUDE的区别? 
答:动态INCLUDEjsp:include动作实现
   <jsp:include page="included.jsp" flush="true" />
它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数
   
静态INCLUDEinclude伪码实现,定不会检查所含文件的变化,适用于包含静态页面
   <%@ include file="included.htm" %>

4
、两种跳转方式分别是什么?有什么区别?
答:有两种,分别为:
  <jsp:include page="included.jsp" flush="true">
  <jsp:forward page= "nextpage.jsp"/>
  
前者页面不会转向include所指的页面,只是显示该页的结果,主页面还是原来的页面。执行完后还会回来,相当于函数调用。并且可以带参数.后者完全转向新页面,不会再回来。相当于go to 语句。

Servlet
方面

1
、说一说Servlet的生命周期?
:servlet有良好的生存期的定义,包括加载和实例化、初始化、处理请求以及服务结束。这个生存期由javax.servlet.Servlet接口的init,servicedestroy方法表达。 

2
JAVA SERVLET APIforward() redirect()的区别?
:前者仅是容器中控制权的转向,在客户端浏览器地址栏中不会显示出转向后的地址;后者则是完全的跳转,浏览器将会得到跳转的地址,并重新发送请求链接。这样,从浏览器的地址栏中可以看到跳转后的链接地址。所以,前者更加高效,在前者可以满足需要时,尽量使用forward()方法,并且,这样也有助于隐藏实际的链接。在有些情况下,比如,需要跳转到一个其它服务器上的资源,则必须使用sendRedirect()方法。 

3
Servlet的基本架构
ExpandedBlockStart.gif ContractedBlock.gif public   class  ServletName  extends  HttpServlet  dot.gif {
InBlock.gif  
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ExpandedSubBlockStart.gifContractedSubBlock.gif      ServletException, IOException  
dot.gif{
ExpandedSubBlockEnd.gif      }

InBlock.gif  
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ExpandedSubBlockStart.gifContractedSubBlock.gif      ServletException, IOException  
dot.gif{
ExpandedSubBlockEnd.gif      }

ExpandedBlockEnd.gif}

None.gif

Jdbc Jdo 方面

1
、可能会让你写一段 Jdbc Oracle 的程序 , 并实现数据查询 .
: 程序如下:
None.gif package  hello.ant;
None.gif
import  java.sql. * ;
None.gif
public   class   jdbc
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif String dbUrl
="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
InBlock.gif String theUser
="admin";
InBlock.gif String thePw
="manager";
InBlock.gif Connection c
=null;
InBlock.gif Statement conn;
InBlock.gif ResultSet rs
=null;
InBlock.gif 
public jdbc() 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif  
trydot.gif{
InBlock.gif    Class.forName(
"oracle.jdbc.driver.OracleDriver").newInstance(); 
InBlock.gif          c 
= DriverManager.getConnection(dbUrl,theUser,thePw);
InBlock.gif    conn
=c.createStatement();
ExpandedSubBlockStart.gifContractedSubBlock.gif  }
catch(Exception e)dot.gif{
InBlock.gif   e.printStackTrace();
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public boolean executeUpdate(String sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     conn.executeUpdate(sql);
InBlock.gif     
return true;
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch (SQLException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     e.printStackTrace();
InBlock.gif     
return false;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public ResultSet executeQuery(String sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif   rs
=null;
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     rs
=conn.executeQuery(sql);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch (SQLException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     e.printStackTrace();
ExpandedSubBlockEnd.gif   }

InBlock.gif   
return rs;
ExpandedSubBlockEnd.gif }

InBlock.gif 
public void close()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     conn.close();
InBlock.gif     c.close();
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif     e.printStackTrace();
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif }

InBlock.gif 
public static void main(String[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  ResultSet rs;
InBlock.gif  jdbc conn 
= new jdbc();
InBlock.gif  rs
=conn.executeQuery("select * from test");
ExpandedSubBlockStart.gifContractedSubBlock.gif  
trydot.gif{
InBlock.gif  
while (rs.next())
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   System.out.println(rs.getString(
"id"));
InBlock.gif   System.out.println(rs.getString(
"name"));
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif  }
catch(Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   e.printStackTrace();
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif

2 Class.forName 的作用 ? 为什么要用 ?
答:调用该访问返回一个以字符串指定类名的类的对象。

3
JDO 是什么 ?
:JDO Java 对象持久化的新的规范,为 java data object 的简称 , 也是一个用于存取某种数据仓库中的对象的标准化 API JDO 提供了透明的对象存储,因此对开发人员来说,存储数据对象完全不需要额外的代码(如 JDBC API 的使用)。这些繁琐的例行工作已经转移到 JDO 产品提供商身上,使开发人员解脱出来,从而集中时间和精力在业务逻辑上。另外, JDO 很灵活,因为它可以在任何数据底层上运行。 JDBC 只是面向关系数据库( RDBMS)JDO 更通用,提供到任何数据底层的存储功能,比如关系数据库、文件、 XML 以及对象数据库( ODBMS )等等,使得应用可移植性更强。

xml,EJB方面:
1
xml有哪些解析技术?区别是什么?
:DOM,SAX,STAX
DOM:
处理大型文件时其性能下降的非常厉害。这个问题是由DOM的树结构所造成的,这种结构占用的内存较多,而且DOM必须在解析文件之前把整个文档装入内存,适合对XML的随机访问SAX:不现于DOM,SAX是事件驱动型的XML解析方式。它顺序读取XML文件,不需要一次全部装载整个文件。当遇到像文件开头,文档结束,或者标签开头与标签结束时,它会触发一个事件,用户通过在其回调事件中写入处理代码来处理XML文件,适合对XML的顺序访问

2.EJB JAVA BEAN 的区别?  
:Java Bean  是可复用的组件,对 Java Bean 并没有严格的规范,理论上讲,任何一个 Java 类都可以是一个 Bean 。但通常情况下,由于 Java Bean 是被容器所创建(如 Tomcat) 的,所以 Java Bean 应具有一个无参的构造器,另外,通常 Java Bean 还要实现 Serializable 接口用于实现 Bean 的持久性。 Java Bean 实际上相当于微软 COM 模型中的本地进程内 COM 组件,它是不能被跨进程访问的。 Enterprise Java Bean  相当于 DCOM ,即分布式组件。它是基于 Java 的远程方法调用( RMI )技术的,所以 EJB 可以被远程访问(跨进程、跨计算机)。但 EJB 必须被布署在诸如 Webspere WebLogic 这样的容器中, EJB 客户从不直接访问真正的 EJB 组件,而是通过其容器访问。 EJB 容器是 EJB 组件的代理, EJB 组件由容器所创建和管理。客户通过容器来访问真正的 EJB 组件。

3
EJB 的基本架构
: 一个 EJB 包括三个部分 :
  Remote Interface 
接口的代码
  package Beans;
  import javax.ejb.EJBObject;
  import java.rmi.RemoteException;
  public interface Add extends EJBObject
  {
   //some method declare 
  }
  Home Interface 
接口的代码
  package Beans;
  import java.rmi.RemoteException;
  import jaax.ejb.CreateException;
  import javax.ejb.EJBHome;
  public interface AddHome extends EJBHome
  {
    //some method declare
  }
  EJB
类的代码
  package Beans;
  import java.rmi.RemoteException;
  import javax.ejb.SessionBean;
  import javx.ejb.SessionContext;
  public class AddBean Implements SessionBean
  {
    //some method declare
  }  

J2EE,MVC
方面

1
MVC 的各个部分都有那些技术来实现 ? 如何实现 ?
:MVC Model View Controller 的简写。 "Model"  代表的是应用的业务逻辑(通过 JavaBean EJB 组件实现),  "View"  是应用的表示面(由 JSP 页面产生), "Controller"  是提供应用的处理过程控制(一般是一个 Servlet ),通过这种设计模型把应用逻辑,处理过程和显示逻辑分成不同的组件实现。这些组件可以进行交互和重用。

2.J2EE 是什么?  
:Je22 Sun 公司提出的多层 (multi-diered), 分布式 (distributed), 基于组件 (component-base) 的企业级应用模型 (enterpriese application model). 在这样的一个应用系统中,可按照功能划分为不同的组件,这些组件又可在不同计算机上,并且处于相应的层次 (tier) 中。所属层次包括客户层 (clietn tier) 组件 ,web 层和组件 ,Business 层和组件 , 企业信息系统 (EIS) 层。

3.STRUTS 的应用 ( STRUTS 架构 )
答: Struts 是采用 Java Servlet/JavaServer Pages 技术,开发 Web 应用程序的开放源码的 framework   采用 Struts 能开发出基于 MVC(Model-View-Controller) 设计模式的应用构架。  Struts 有如下的主要功能:  
. 包含一个 controller servlet ,能将用户的请求发送到相应的 Action 对象。  
.JSP 自由 tag 库,并且在 controller servlet 中提供关联支持,帮助开发员创建交互式表单应用。  
. 提供了一系列实用对象: XML 处理、通过 Java reflection APIs 自动处理 JavaBeans 属性、国际化的提示和消息
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值