山东浪潮齐鲁软件产业股份有限公司-高级Java软件工程师笔试题

来源:互联网 发布:淘宝卖大米 编辑:程序博客网 时间:2024/05/16 23:38

山东浪潮齐鲁软件产业股份有限公司

高级Java软件工程师笔试题

 

选择题

1、 关于垃圾收集的那些叙述是对的

A、程序开发者必须自己创建一个线程进行内存释放的工作

B、 垃圾收集将检查并释放不再使用的内存。

C、垃圾收集允许程序开发者明确指定并立即释放该内存

D、垃圾收集能够在期望的时间释放被java对象使用的内存

答案B

  解析Java语言将内存分配和释放的工组交给了自己,程序员不必做这些工作,它提供一个系统级的线程跟踪每个内存的分配,在JVM的空闲处理中,垃圾收集线程将检查和释放不再使用的内存(即可以被释放的内存)。垃圾收集的过程在java程序的生存期中是自动的,不需要分配和释放内存,也避免了内存泄漏。可以调用Systemgc()方法建议(suggestJVM执行垃圾收集以使得可被释放的内存能立即被使用,当此方法返回的时候,JVM已经做了最大的努力从被丢弃的对象上回收内存空间。程序员不能指定收集哪些内存,一般而言也不用关心这个问题,除非是程序的内存消耗很大,特别是有很多临时对象时可以建议进行垃圾收集以提高可用内存。需要指出的是调用Systemgc()方法不能保证JVM立即进行垃圾收集,而只能是建议,因为垃圾收集线程的优先级很低(通常是最低的)。

 

2、 在软件生命周期中,下列哪个说法是不准确的?

A、软件生命周期分为计划、开发和运行三个阶段

B、 在计划阶段要进行问题研究和需求分析

C、在开发后期要进行编写代码和软件测试

D、在运行阶段主要是进行软件维护

 

3、 Give the following java class:

Public classExample{

static intx[]=new int[15];

public staticvoid main(String args[])

{

        System.out.println(x[5]);

}

}

Which statementis corrected?

A、When compile,some error willoccur.    A  Static int x[]有问题

B、When run,some error will occur.

C、Output is zero

D、Output is null

4、 设有变量说明语句int a=1,b=0;

则执行以下程序段的输出结果为()

Switch(a)

{

case 1:

 switch(b)

{

      case 0:printf(“**0**”);break;

      case 1:printf(“**1**”);break;

}

Case 2:printf(“**2**”);break;

}

Printf(“\n”);

A、**0**

B**0****2**

C、**0****1****2**

D、有语法错误

   *0** **2**;

先输出0,由于最外面case1 没Break,所以继续case2,输出2;

5、 What is written to thestandard output given the following statement : System.out.println(4 | 7);

Select the rightanswer:

       A、4

       B、5

       C、6

       D7

|”是按位或运算符,先将47转为二进制数。转换后就是计算“100|111”,所以得到结果是“111”,转为十进制整形数是7。此题提醒考生注意,要熟悉各种运算符号的含义

6、 Which method you define as thestarting point of new thread in a class from which new the thread can beexcution?

A、    public void start()

B、   public void run()

C、    public void runnable()

D、    public static void main(String args[])

线程的执行是从方法“run( )”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态。

7.Which are not Java keywords?

A.TRUE

B.const

C.super

D.void

 

8.What will happen when you attempt tocompile and run the following code?

(Assume that the code is compiled and runwith assertions enabled)

public class AssertTest{

public void methodA(int i){

assert i>=0:methodB();

System.out.println(i);

}

public void methodB(){

System.out.println(“The value must not benegative”);

}

public static void main(String[] args){

AssertTest test = new AssertTest();

Test.methodA(-10);

}

}

A.    will print -10;

B.     it will result inAssertionError showing the message “the value must not be negative”.

C.     The code will not compile

D.    None of these

9.Which of the following statements aretrue?

A.The automatic garbage collection of theJVM prevents programs from ever running out of memory java虚拟机的自动垃圾回收机制可以避免内存不足的情况发生。

B.A program can suggest that garbage collection be performed and forceit.

C.Garbage collection is platformindependent.

D.An object become eligible for garbage collection when all referencesdenoting it are set to null.

 

10、What will happen when you attempt to compile and run the followingcode ?

Class Base{

       inti=99;

public void amethod()

{

       System.out.println(“Base.amethod()”);

}

Base()

{

       Amethod();

}

}

Public class Derived extends Base

{

       Inti=-1;

       Publicstatic void main(String  argv[])

{

              Base b =new Derived();

              System.out.println(b.i);

b.amethod();

}

Public void amethod()

{

       System.out.println(“Derived.amethod()”);

}

}

Choices:

A.    Derived.amethod()-1Derived.amethod()

B.     Derived.amethod() 99 Derived.amethod()

C.     Compile time error

D.    Derived.amethod()

 

11.when is the float object created in line3,eligible(合适的, 适当的) for garbage collection ?

1.public classX{

2 public objectm(){

3. object o=newfloat(3.14F);

4. object []oa =new object[1];

5. oa[0]=o;

6. o=null;

7. oa[0] = null;

8. return 0;

9. }

10.}

  1. Just after line 5
  2. Just after line 6
  3. Juest after line 7
  4. Just after line 8(that is ,as the method returns)

 

12:What will happen when you attempt tocompile and run the following code?

Public class static

{

Static

{

Int x=5;

}

Static int x,y;

Public static void main(string args[])

{

       x--;

       myMethod();

       System.out.println(x+y +++x);

}

Public static void myMethod()

{

       Y=x++ + ++x;

}

}

Choices:

A.    PRINTS:2

B.     PRINTS:3

C.     PRINTS:7

D.    PRINTS:8

 

13. which code fragments(碎片; 片断)would correctly identify the number of arguments passed via command line to ajava application ,exclude the name of class that is being invoke.

       A.int count=args.length;

       B.int count =args.length-1;

       C.intcount=0;while(args[count]!=null) count++;

D.intcount=0;while(!(args[count].equals(“”))) count++;

args[count]null调用equals方法会出现nullpointexception

14:Select valid identifier of java:

A.    %passwd

B.     3d_game

C.     $charge

D.    This

 

15:鉴于java的特点,它最适合的计算机环境是

A.    并行计算环境

B.     分布式计算环境

C.     高亮度计算环境

D.    开放式计算环境

 

16 软件声明者后期的瀑布模型吧软件项目分为三个阶段,8个子阶段,以下哪一个是正常的开发顺序?

       A.计划阶段、开发阶段、运行阶段

       B.设计阶段、开发阶段、编码阶段

       C.涉及阶段、编码阶段、维护阶段

D. 计划阶段、编码阶段、测试阶段

 

17 what will be the result of executing thefollowing code?

//filename;superclass X.java

Package package X;

Public class SuperclassX;

{

       Protectedvoid superclassMethodX()

{

}

Int superclass VarX;

//Filename Subclass Y.java

1.      package package X.package Y;

2.       

3.      public class SubclassY extendsSuperclassX

4.      {

5.      SuperclassX objX =newSubclassY();

6.      SubclassY objY = newSubclassY();

7.      void subclassMethodY()

8.      {

9.      objY.superclassMethodX();

10.  int i;

11.  i=objY.superclass VarX;

12.  }

13.  }

Choices:

 

A.    Compilation error at line 5

B.     Compilation error at line 9

C.     Runtime exception at line 11

D.    None of these

错在你定义的 int superclassVarX protected访问权限,在不同的包里是访问不了的,如果两个类在同一个包里就可以访问,如果在两个不同的包中就改成public就可以访问了  c is correct.The explanation in English isclear,and i think you have some misunderstanding.
juding from the example above,the type of reference decides access, not thetype of object.

the type of objectY is subclassY(via references of its own type )
the type of objectX is superclassX(neither references of its own type nor asubtype).

 

18:When is the Float object,created in line 3,eligible forgarbage collection?

Public clas X{

       PublicObject m(){

              Objecto = new Float(3.14F);//line 3

              Object[]oa = new Object[1]; //line4

oa[0] = o; //line 5

o = null; //line 6

return oa[0]; //line7

}

}

When is the Float object ,created in line3,eligible for garbage collection?

  1. just after line 5
  2. just after line 6
  3. just after line 7(that is, as the method returns)
  4. never in this method

 

19:Which of the following statements arenot legal?

 

A.    long l = 4990;

B.     int I = 4L;

C.     double d = 34.4;

D.    double t = 0.9F;

 

20:

What is the result when you compile and runthe following code?

Public class Test

{

       publicvoid method()

{

              for(int  i = 0;i < 3;i++)

{

 

              System.out.print(i);

}

System.out.print(i);

}

}

Choices:

A.    0122

B.     0123

C.     Compilation error

D.    None of these

 

简答题

21:什么情况下调用doGet()和doPost()?

jsp页面的formmethod属性决定。methodget时调用doGet,为post时调用doPost

22:金额转换,阿拉伯数字的金额转换成中国传统的形式如:

(¥1011)-->(一千零一拾一元整)输出

importjava.text.NumberFormat;
import java.util.HashMap;
import java.lang.StringBuffer;

public classSimpleMoneyFormat {

public static finalString EMPTY="";
public static final String ZERO="零";
public static final String ONE="壹";
public static final String TWO="贰";
public static final String THREE="叁";
public static final String FOUR="肆";
public static final String FIVE="伍";
public static final String SIX="陆";
public static final String SEVEN="柒";
public static final String EIGHT="捌";
public static final String NINE="玖";
public static final String TEN="拾";
public static final String HUNDRED="佰";
public static final String THOUSAND="仟";
public static final String TEN_THOUSAND="万";
public static final String HUNDRED_MILLION="亿";
public static final String YUAN="元";
public static final String JIAO="角";
public static final String FEN="分";
public static final String DOT=".";

private static SimpleMoneyFormat formatter=null;
private HashMap chineseNumberMap=new HashMap();
private HashMap chineseMoenyPattern=new HashMap();
private NumberFormat numberFormat=NumberFormat.getInstance();

//私有构造函数
private SimpleMoneyFormat() {
numberFormat.setMaximumFractionDigits(4);
numberFormat.setMinimumFractionDigits(2);
numberFormat.setGroupingUsed(false);

chineseNumberMap.put("0",ZERO);
chineseNumberMap.put("1",ONE);
chineseNumberMap.put("2",TWO);
chineseNumberMap.put("3",THREE);
chineseNumberMap.put("4",FOUR);
chineseNumberMap.put("5",FIVE);
chineseNumberMap.put("6",SIX);
chineseNumberMap.put("7",SEVEN);
chineseNumberMap.put("8",EIGHT);
chineseNumberMap.put("9",NINE);
chineseNumberMap.put(DOT,DOT);

chineseMoenyPattern.put("1",TEN);
chineseMoenyPattern.put("2",HUNDRED);
chineseMoenyPattern.put("3",THOUSAND);
chineseMoenyPattern.put("4",TEN_THOUSAND);
chineseMoenyPattern.put("5",TEN);
chineseMoenyPattern.put("6",HUNDRED);
chineseMoenyPattern.put("7",THOUSAND);
chineseMoenyPattern.put("8",HUNDRED_MILLION);
}

//单例模式
public static SimpleMoneyFormat getInstance(){
if(formatter==null)
formatter=new SimpleMoneyFormat();
return formatter;
}

public String format(String moneyStr){
checkPrecision(moneyStr);
String result;
result=convertToChineseNumber(moneyStr);
result=addUnitsToChineseMoenyString(result);
return result;
}

public String format(double moneyDouble){
return format(numberFormat.format(moneyDouble));
}

public String format(int moneyInt){
return format(numberFormat.format(moneyInt));
}

public String format(long moneyLong){
return format(numberFormat.format(moneyLong));
}

public String format(Number moneyNum){
return format(numberFormat.format(moneyNum));
}

private String convertToChineseNumber(String moneyStr){
String result;
StringBuffer cMoneyStringBuffer =new StringBuffer();
for(int i=0;i<moneyStr.length();i++){
cMoneyStringBuffer.append(chineseNumberMap.
get(moneyStr.substring(i,i+1)));
}

int indexOfDot=cMoneyStringBuffer.indexOf(DOT);
int moneyPatternCursor=1;
for(int i=indexOfDot-1;i>0;i--){
cMoneyStringBuffer.insert(i,
chineseMoenyPattern.get(EMPTY+moneyPatternCursor));
moneyPatternCursor=moneyPatternCursor==
8?1:moneyPatternCursor+1;
}

String fractionPart=cMoneyStringBuffer.substring(
cMoneyStringBuffer.indexOf("."));
cMoneyStringBuffer.delete(
cMoneyStringBuffer.indexOf("."),
cMoneyStringBuffer.length());
while(cMoneyStringBuffer.indexOf("零拾")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零拾"),
cMoneyStringBuffer.indexOf("零拾")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零佰")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零佰"),
cMoneyStringBuffer.indexOf("零佰")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零仟")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零仟"),
cMoneyStringBuffer.indexOf("零仟")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零万")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零万"),
cMoneyStringBuffer.indexOf("零万")+2,TEN_THOUSAND);
}
while(cMoneyStringBuffer.indexOf("零亿")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零亿"),
cMoneyStringBuffer.indexOf("零亿")+2,HUNDRED_MILLION);
}
while(cMoneyStringBuffer.indexOf("零零")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零零"),
cMoneyStringBuffer.indexOf("零零")+2,ZERO);
}
if(cMoneyStringBuffer.lastIndexOf(ZERO)
==cMoneyStringBuffer.length()-1){
cMoneyStringBuffer.delete(
cMoneyStringBuffer.length()-1,
cMoneyStringBuffer.length());
}
cMoneyStringBuffer.append(fractionPart);
result=cMoneyStringBuffer.toString();
return result;
}

private String addUnitsToChineseMoenyString(String moneyStr){
String result;
StringBuffer cMoneyStringBuffer=new StringBuffer(moneyStr);

int indexOfDot=cMoneyStringBuffer.indexOf(DOT);
cMoneyStringBuffer.replace(indexOfDot,indexOfDot+1,YUAN);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length()-1,JIAO);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length(),FEN);

//拾佰仟万亿等都是汉字里面才有的单位,加上它们
if(cMoneyStringBuffer.indexOf("零角零分")!=-1)//去掉零头,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零角零分"),
cMoneyStringBuffer.length(),"整");
else if(cMoneyStringBuffer.indexOf("零分")!=-1)//去掉零分,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零分"),
cMoneyStringBuffer.length(),"整");
else if(cMoneyStringBuffer.indexOf("零角")!=-1)
cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("零角"),
cMoneyStringBuffer.indexOf("零角")+2);
result=cMoneyStringBuffer.toString();
return result;
}

//检查精度的合法性
private void checkPrecision(String moneyStr){
int fractionDigits=moneyStr.length()-moneyStr.indexOf(DOT)-1;
if(fractionDigits>2)//精度不能比分低
throw new RuntimeException("金额"+moneyStr+"的小数位数多余两位.");
}

public static void main(String[] args){
System.out.println(getInstance().format(new Double(10010001.01)));
}

}

 

23:spring的容器的实际代表者是哪个类(接口),该类常见的子类有哪些?

BeanFactory接口是SpringIoC容器的实际代表者。 IoC容器负责容纳此前所描述的bean,并对bean进行管理。ApplicationContextBeanFactory的子类,所以大多数的用户更喜欢使用ApplicationContextXML形式)。

24:指出下面代码的错误,说明原因。

interface A{

       intx = 0;

}

class B{

       intx = 1;

}

class C extends B implements A{

       publicvoid pX(){

              System.out.println(x);

}

public staticvoid main(String[] args){

       New C().pX();

}

}

25:现有两个文件,

a)      数据文件A,格式为:关键词、IP地址、时间,记录条数为1000万左右,该文件是无序排列的。

b)     数据文件B是关键词ID到关键词的对应表文件,格式为:ID、关键词,记录条数在100万左右,也是无序排列的。该对应表中的记录是一一对应的,不存在ID或者关键词重复的情况。

 

要求将数据文件A对应的关键词替换为B中的ID,生成新的数据文件C,数据文件C的格式为:关键词ID、IP地址、时间。

请设计一个程序,实现上述功能,并分析时间复杂度和空间复杂度。运行程序所使用的服务器内的内存为1G,硬盘足够大。(至少要给出关键算法和设计思路)

我觉得这个用hash数组比较好
首先建立一个int a[1000000],这一步使用4x1000000=4M
然后写一个hash函数,将b文件按照关键字=>关键ID”进行映射这一步时间复杂度为 O(n) 空间复杂度为O(n)

剩下的事情就是分配读入a文件,然后顺序分析每一行,并将结果追加进c文件这一步时间复杂度为O(N)空间复杂度视乎你读取文件所用的缓存,如果是我,我选择读取100000行,那空间复杂度为O(N/100000)
总的时间复杂度为 O(n+N)
总的空间复杂度为 O(n+N/100000)
这个关键在于选择一个好的hash算法,并注意处理冲撞的问题。hash查找的时间复杂度为O(1)

当然因为a文件是无序的,而且输出的c文件也没有要求是有序的,因此,可以用多进程或者多线程,对文件进行分割替换,这在多cpu服务器上会显著增加速度,但是,会增加空间的占用,不过1G的内存空间足够了。

一个Java代码的实例:

package org.jyjiao.test1;

 

import java.io.*;

import java.util.*;

 

public class ReplaceKeyWord {

       StringfileA, fileB, fileC;

       HashMap<String,Integer>map;

       publicReplaceKeyWord(String fileA, String fileB, String fileC) {

              this.fileA= fileA;

              this.fileB= fileB;

              this.fileC= fileC;

              map= new HashMap<String,Integer>();

       }

 

       publicvoid replace() {

              try{

                     BufferedReaderbrA = new BufferedReader(new FileReader(fileA));

                     BufferedReaderbrB = new BufferedReader(new FileReader(fileB));

                     BufferedWriterbwC = new BufferedWriter(new FileWriter(fileC));

                     //iniciate hashmap (时间复杂度:O(1M),空间复杂度:O(1M))

                     Stringstr;

                     while((str = brB.readLine()) != null) {

                            str.trim();

                            String[]tmpB = new String[2];

                            tmpB= str.split("");

                            map.put(tmpB[1],newInteger(tmpB[0]));

                     }

                    

                     //input fileC (时间复杂度:O(10M),空间复杂度:O(1))

                     while((str = brA.readLine()) != null) {

                            str.trim();

                            String[]tmpA=str.split("");

                           

                            String key=tmpA[0];

                            if(map.containsKey(key)){

                                   Integerid=map.get(key);

                                   str=id+""+tmpA[1]+""+tmpA[2];

                                   bwC.write(str);

                                   bwC.newLine();

                            }

                     }

                    

                     brA.close();

                     brB.close();

                     bwC.flush();

                     bwC.close();

                    

              }catch (IOException ex) {

                     ex.printStackTrace();

              }finally {

 

              }

       }

 

       publicstatic void main(String[] args) {

              StringfileA="D:\\fileA.txt";

              StringfileB="D:\\fileB.txt";

              StringfileC="D:\\fileC.txt";

              ReplaceKeyWordrk=new ReplaceKeyWord(fileA,fileB,fileC);

              rk.replace();

       }

 

}

 

26:jsp有哪些动作?作用分别是什么?

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

27:说出Servlet的生命周期,并说出Servlet和CGI的区别。

Servlet被服务器实例化后,容器运行其init方法,请求到达时运行其service方法,

service方法自动派遣运行与请求对应的doXXX方法(doGetdoPost)等,当服务器决定

将实例销毁的时候调用其destroy方法。

cgi的区别在于servlet处于服务器进程中,它通过多线程方式运行其service方法,

一个实例可以服务于多个请求,并且其实例一般不会销毁,而CGI对每个请求都产生新的进程,

服务完成后就销毁,所以效率上低于servlet

28:对象流只能读/写对象吗?不能读/写其它数据吗?为什么?

“对象序列化”(ObjectSerialization)是Java1.1就开始有的特性。简单地说,就是可以将一个对象(标志对象的类型)及其状态转换为字节码,保存起来(可以保存在数据库,内存,文件等),然后可以在适当的时候再将其状态恢复(也就是反序列化)serialization不但可以在本机做,而且可以经由网络操作。它自动屏蔽了操作系统的差异,字节顺序等

30:写一个程序,把一个100以内的自然数分解因数。(自然数分解因数就是将一个自然数为几个素数的乘积,提示,由于该数不是很大,所以可以质数保存在数组中,以加快计算速度)

Java算法一个正整数分解质因数

题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5  

程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成:  

(1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。 

(2)如果n<> k,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数你,重复执行第一步。  

(3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。  

public class exp2{

       public exp2(){}

    public void fengjie(intn){

        for(int i=2;i<=n/2;i++){

            if(n%i==0){

                System.out.print(i+"*");

               fengjie(n/i);

                }

        }

        System.out.print(n);

        System.exit(0);///不能少这句,否则结果会出错

        }

        public static voidmain(String[] args){

             Stringstr="";

             exp2 c=new exp2();

            str=javax.swing.JOptionPane.showInputDialog("请输入N的值(输入exit退出):");

             int N;

             N=0;

             try{

                    N=Integer.parseInt(str);

                     }catch(NumberFormatException e){

                        e.printStackTrace();

                        }

            System.out.print(N+"分解质因数:"+N+"=");

           c.fengjie(N);

        }   

}

 

 

 

一个简单的论坛系统,以数据库储存如下数据:
用户名,email,主页,电话,联系地址,发帖标题,发帖内容,回复标题,回复内容。
每天论坛访问量300万左右,更新帖子10万左右。
请给出数据库表结构设计,并结合范式简要说明设计思路。

此题主要是考核web设计中面临数据量较大的表设计
我以mysql为例来设计表(呵呵,最近用得最多)
用户名(username)email(mail),主页(homepage),电话(tel),联系地址(address),发帖标题(title),发帖内容(context)(回复标题(),回复内容)实际上是对应于发帖的。
由于数据并发量较大.所以表需要尽可能的减少表查询量.我的设计如下


user
create table usertable{
id int(11) auto_increment,
username varchar(255),
mail varchar(255),
homepage varchar(255),
tel varchar(255),
address varchar(255),
primary key(id),key(username)
}
alter table usertable add index id_idex(id);//
id建立索引
alter table usertable add index username_idex(username);//
id建立索引

帖子表.其中的用户信息是和user表的用户信息同步.这样保证了查询表的次数
create table posttext{
id int(11) auto_increment,
title varchar(255) not null,
context text ,
user_id int(11),
username varchar(255),//
此处需要加入页面显示的基本信息.这样每个帖子的查询就只需要涉及一个表的操作
mail varchar(255),
homepage varchar(255),
is_topic enum(1,0) default 0,
primary key(id)
}
alter table posttext add index id_idex(id);//
给帖子id建立索引
alter table posttext add index id_idex(user_id);//
给用户表id建立索引

 

 

 

 

      

0 0