网龙笔试题:
1、实现链表的创建,删除和逆序等。
#include<iostream>
#include<>
using namespace std;
typedef struct stu
{
int data;
struct stu *next;
}node, list;
node* creatlist(int n)
{
node *h, *p, *s;
h = new node;
h->next = NULL;
p = h;
cout << “please input ” << n << ” numbers.”;
for(int i = 0; i < n; i++)
{
s= new node;
cin >> s->data;
s->next = NULL;
p->next = s;
p = s;
}
return h;
}
void deletelist (node *s, int a)
{
node *p;
while(s->data != a)
{
p = s;
s = s->next;
}
if(s == NULL)
{
cout << “no a”;
}
else
{
p->next = s->next;
delete s;
}
}
void display(node *h)
{
h = h->next;
while(h != NULL)
{
cout << h->data << ends;
h = h->next;
}
cout << endl;
}
node* reverse(node* h)
{
node *p, *q, *s;
p = h->next;
q = p->next;
while(q->next != NULL)
{
s = q->next;
q->next = p;
p = q;
q = s;
}
q->next = p;
h->next->next = NULL;
h->next = q;
return h;
}
int main()
{
int n;
node *h;
cout << “please input the number:”;
cin >> n;
h= creatlist(n);
display(h);
cout << “delete ?”;
cin >> n;
deletelist(h, n);
display(h);
h = reverse(h);
display(h);
return 0;
}
2、字符串逆序
输入文件是 ,内容例如如下:
hello, everyone.
my name is shen, he.
ni, ne?
则倒序之后为:
everyone. hello,
he. shen, is name my
ne? ni,
源程序,自己实现的,算法是别人的。呵呵
#include<iostream>
#include<fstream>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
char *fName;
string::size_type b,e;
char ch;
string line;
vector<string> svec;
(””);
while(getline(inFile, line)) //先获取每一行字符,并存入容器中
{
_back(line);
}
();
(””);
vector<string>::iterator iter = ();
while(iter != ())
{
b = 0;
e = (*iter).size() – 1;
while( b < e) //将该行字符整体翻转
{
ch = (*iter)[b];
(*iter)[b] = (*iter)[e];
(*iter)[e] = ch;
b++;
e–;
}
b = 0;
e = 0;
string::size_type i = 0;
while( (*iter)[i] )
{
if((*iter)[i] != ‘ ‘) //找到一行的一个单词
{
b = i;
while((*iter)[i] != ‘ ‘ && (*iter)[i])
i++;
i–;
e = i;
}
while (b < e) //将这个单词翻转
{
ch = (*iter)[b];
(*iter)[b] = (*iter)[e];
(*iter)[e] = ch;
b++;
e–;
}
i++;
}
outFile << *iter << endl;
++iter;
}
return 0;
}
新大陆面试题:
(一)技术面试
struts 如何表现 MVC 模式的?
Tomcat 的部署?
UML 有哪些图?
Struts 框架的好处(优点)?
答:1、是开源软件,使开发者能更深入的了解其内部实现机制。
2、Taglib 是 Struts 的标记库,灵活动用,能大大提高开发效率;通过一个配置文件,
即可把握整个系统各部分之间的联系,这对于后期的维护有着莫大的好处。尤其是当另一批
开发者接手这个项目时,这种优势体现得更加明显。
4. 提供 Exception 处理机制 .
5. 数据库链接池管理
6. 支持 I18N
Struts+Hibernate 框架的优势?
答:这两种架构相结合很好地解决了系统的开发效率低、不易于维护、低耦合及可移植性差
等问题.
介绍一下 AJAX?
答:AJAX(Asynchronous JavaScript and XML)被赢得广泛的认可,其原因是由于它缩短了
Web 应用程序和桌面应用程序之间的差距,并在其中充分结合可实现的技术和丰富的用户
体验。
AJAX 是多种技术的综合,它打破了页面刷新的范式,使您的用户快速方便的与 Web 应用
程序交互。
CVS 配置与使用?
POJO 是什么?
答:简单的 Java 对象(Plain Old Java Objects),POJO 对象有时也被称为 Data 对象,大量应
用于表现现实中的对象。
概要设计与详细设计等文档的主要包含内容?
(二)笔试内容
Java 基础:Char 变量.ClassLoader 与 .等
SQL 方面:SQL 全称.查询语句. Group by . set
JSP 方面:静态 include 与动态 include
第一部分: Java 基础知识
1.
What will happen when you attempt to compile and run the following code?
public class Test {
static {
int x = 5;
}
static int x, y;
public static void main(String args[]) {
x--;
myMethod();
(x + y + ++x);
}
public static void myMethod() {
y = x++ + ++x;
}
}
A. compiletime error
B. prints: 1
C. prints: 2
D. prints: 3
E. prints: 7
F. prints: 8
2.
Which of the following collection classes from package are Thread safe? (Choose two)
A. Vector
B. ArrayList
C. HashMap
D. Hashtable
3.
Which of the following types is primitive java type?(Choose two)
A String
B int
C char
D Short
4.
Which two demonstrate a "has a" relationship? (Choose two)
A. public interface Person { }
public class Employee extends Person{ }
B. public interface Shape { }
public interface Rectandle extends Shape { }
C. public interface Colorable { }
public class Shape implements Colorable { }
D. public class Species{ }
public class Animal{private Species species;}
E. interface Component{ }
class Container implements Component{
private Component[] children;
}
5. What is the result when you compile and run the following code?
public class ThrowsDemo {
static void throwMethod() {
("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
("Caught " + e);
}
}
}
A. compile error
B. runtime error
C. compile successfully, nothing is printed.
D. inside throwMethod followed by caught: : demo
6.
Which two statements are true for the class ? (Choose two)
A. The elements in the collection are ordered.
B. The collection is guaranteed to be immutable.
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E. The elements in the collection are guaranteed to be synchronized
点评:TreeSet 类实现了 Set 接口。Set 的特点是其中的元素惟一,选项 C 正确。由于采用了树形存储方式,
将元素有序地组织起来,所以选项 A 也正确。
7. What will be printed when you execute the following code?
class X {
Y b = new Y();
X() {
("X");
}
}
class Y {
Y() {
("Y");
}
}
public class Z extends X {
Y y = new Y();
Z() {
("Z");
}
public static void main(String[] args) {
new Z();
}
}
A. Z
B. YZ
C. XYZ
D. YXYZ
8. which two declaretions prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
9. You want a class to have access to members of another class in the same package which is
the most restrictive access modifier that will accomplish this objective?
A. public
B. private
C. protected
D. transient
E. No access modifier is required
10. which two interfaces provide the capability to store objects using a key-value pair?
A.
B.
C.
D.
E.
F.
11.
1) class Super{
2) public float getNum(){return ;}
3) }
4)
5) public class Sub extends Super{
6)
7) }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return ;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return ;}
注意这道题主要考的是方法的 overload 和 override。对于 overload,只有参数列表不同,才做为标准,而
返回值和访问控制关键字不能做为标准,所以 B 错在方法名相同,但只有返回值不同,这是错的。C 和 D
是正确的 overload。对于 override,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常
的子类,也可以不抛出。返回类型,参数列表必须精确匹配。所以 A 是正确的 override。
12.
which gets the name of the parent directory of file ""?
A. String name=("");
B. String name=(new File("")).getParent();
=(new File("")).getParentName();
=(new File("")).getParentFile();
=(new File("")).getParentDir();
String name=();
13.
What happens when you try to compile and run the following application? Choose all correct options.
1. public class Z {
2. public static void main(String[] args) {
3. new Z();
4. }
5.
6. Z() {
7. Z alias1 = this;
8. Z alias2 = this;
9. synchronized(alias1) {
10. try {
11. ();
12. (“DONE WAITING”);
13. }
14. catch (InterruptedException e) {
15. (“INTERR UPTED”);
16. }
17. catch (Exception e) {
18. (“OTHER EXCEPTION”);
19. }
20. finally {
21. (“FINALLY”);
22. }
23. }
24. (“ALL DONE”);
25. }
26. }
A. The application compiles but doesn't print anything.
B. The application compiles and print “DONE WAITING”
C. The application compiles and print “FINALLY”
D. The application compiles and print “ALL DONE”
E. The application compiles and print “INTERRUPTED”
点评:在 Java 中,每一个对象都有锁。任何时候,该锁都至多由一个线程控制。由于 alias1 与 alias2 指向
同一对象 Z,在执行第 11 行前,线程拥有对象 Z 的锁。在执行完第 11 行以后,该线程释放了对象 Z 的锁,
进入等待池。但此后没有线程调用对象 Z 的 notify()和 notifyAll()方法,所以该进程一直处于等待状态,没
有输出。
14. What results from attempting to compile and run the following code?
public class Ternary{
public static void main(String args[]){
int a = 5;
("Value is - " + ((a < 5) ? : 9));
}
}
A. print:Value is -9
B. print:Value is -5
C. Compilation error
D. None of these
第二部分: JSP & Servlet
15. Which is the correct code segment?
A <%@ include file="" %>
B <%@ include page ="" %>
C <jsp:include page="" />
D <jsp:include file ="" />
16. which code segment make the servlet engine use the singleThreadModel interface ?
A. <%@ page isThreadSafe="false"%>
B. <%@ page isThreadSafe="true"%>
C. <%@ page setThreadSafe="false"%>
D. <%@ page setThreadSafe ="true"%>
17. 在 servlet 和 EJB 之间传递的 valueObject 对象类要继承什么接口
Serializable
18. 我们在 web 应用开发过程中经常遇到输出某种编码的字符,如 iso-8859-1 等,如何用
getBytes 输出一个某种编码的字符串?
(1)请写出使用 getBytes 方法进行编码转换的代码(一句示例即可)
("ISO8859_1")
(2)在处理 servlet 的中文问题时,除上面的方法外,是否有别的常用办法
("GB2312");,
19. EJB 分为几种哪三种 EJB,其中的两种又可各细分成另外两种,写出 7 种分类
Session Bean,Entity Bean,MessageDriven Bean
Session bean: Stateful session bean, Stateless session bean
Entity Bean: Bean-Managed Persistence Container-Managed Persistence
20. 简述 forward 和 redirect 的区别
第三部分: 系统设计
21. UML 中,通常意义上的静态图,交互图 分别包含下列哪些图(多选)
A 用例图
B 类图
C 对象图
D 行为图
E 顺序图
F 合作图
G 实现图
H 包图
静态图( ABC )
交互图( DEFG )
22. 写一种单体类(Singleton)实现实例
23.写一种 Factory 的实现实例。