广州面试题------爱立信01
1. Which statement is true?( )
public void test(int x) {
int odd = 1;
if (odd) {
System.out.println("odd");
} else {
System.out.println("even");
}
}
(A) "odd" will always be output.
(B) "even" will always be output.
(C) Compilation fails.
(D) "odd" will be output for odd values of x, and "even" for even values.
2. Which one is not valid IP address ?
(A) 192.168.0.254 (B) 192.168.0.255 (C) 192.168.255.254 (D) 192.168.0.256
3. Select the one correct answer. The number of characters in an object of a class String is given by( )
(A) The member variable called size.
(B) The member variable called length
(C) The method size() returns the number of characters.
(D) The method length() returns the number of characters.
4. Which code determines the int value data closer to, but not greater than, a double value b? ( )
(A) Int data = (int) Math.floor(b);
(B) Int data = (int) Math.abs(b);
(C) Int data = (int) Math.ceil(b);
(D) Int data = (int) Math.min(b);
5. Linux file permission setting is presented by one string which length is 10,
it can be divided into 4 parts from left to right, So what is the meaning of the part 3 ?
Such as "drwxrwxr-x" => part1:"d", part2:"rwx", part3:"rwx", part4:"r-x"
(A) file type (B) permissions of file owner (C) permissions of file owner's group (D) permissions of other users
6. What will be the output of the program? ( )
public class X {
public static void main(String[] args) {
try {
badMethod();
System.out.print("A");
} catch (RuntimeException ex) {
System.out.print("B");
} catch (Exception ex1) {
System.out.print("C");
} finally {
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod() {
throw new RuntimeException();
}
}
(A) BD
(B) BCD
(C) B
(D) BDE
7. What is valid returnType for getData? ( )
public class ReturnData {
<returnType> getData(byte a, double z) {
return (a / z) * 10;
}
}
(A) short (B) byte (C) int (D) double
8. What is the result? ( )
public static void main(String[] args) {
int index = 1;
Boolean[] test = new Boolean[3];
boolean data = test[index];
System.out.println(data);
}
(A) true (B) false (C) null (D) NullPointerException
9. What is the output? ( )
public class Accessment implements Cloneable, Comparable<Accessment> {
int value = 1;
public static void main(String[] args) throws CloneNotSupportedException {
Accessment a = new Accessment();
Accessment b = change1(a);
Accessment c = change2(b);
System.out.println((a == b) + "," +
(a == c) + "," +
(b == c) + "," +
a.equals(c));
}
static Accessment change2(Accessment b) throws CloneNotSupportedException {
Accessment result = (Accessment) b.clone();
return result;
}
static Accessment change1(Accessment a) {
a.setValue(2);
return a;
}
public void setValue(int value) {
this.value = value;
}
public int compareTo(Accessment o) {
return this.value - o.value;
}
public boolean equals(Object obj) {
return this.compareTo((Accessment) obj) == 0;
}}
(A) true,false,false,true
(B) false,false,true,false
(C) true,true,false,true
(D) false,true,true,false
10. Here is a network 192.168.1.0/24,the gateway is 192.168.1.1。
when server 192.168.1.20 want to communicate with network 172.16.1.0/24,
which one is the right route setting:
(A) route add –net 192.168.1.0 gw 192.168.1.1 netmask 255.255.255.0 metric 1
(B) route add –net 172.16.1.0 gw 192.168.1.1 netmask 255.255.255.255 metric 1
(C) route add –net 172.16.1.0 gw 172.16.1.1 netmask 255.255.255.0 metric 1
(D) route add default 192.168.1.0 netmask 172.168.1.1 metric 1
Part II Multiple Selection (3 score per question)
1. In OSI 7 layers model, which one will be included?
(A) Physical Layer
(B) Abstract Layer
(C) Interface Layer
(D) Transport Layer
(E) Session Layer
2. Linux is which kind of Operating System?
(A) Multi User
(B) Multi Tasking
(C) Multi Process
(D) All of the above
(E) None of the above
3. Run statements below, return false item(s) ( )
String a = "hello";
String b = "hello";
String c = new String("hello");
char d[] = {'h','e','l','l','o'};
(A) System.out.println(a==b);
(B) System.out.println(a==c);
(C) System.out.println(a==d);
(D)System.out.println(a.equals(d));
4. The wrong statement(s) ( )
(A) constructor in class can’t ignore
(B) constructor name must same with class name,but method name can’t same with class name
(C) constructor called when call object new
(D) one class only has one constructor
5. The method(s) in Thread class ( )
(A) start() (B) run() (C) exit() (D) getPriority()
6. Which of the following class belongs to the char type stream ( )
(A) BufferedWriter
(B) FileInputStream
(C) ObjectInputStream
(D) InputStreamReader
7. Java interface modifiers include ( )
A private B protected C final D abstract
8. In Red hat which config file responsible for ip domain name resolution?
(A) /etc/hosts
(B) /etc/resolv.conf
(C) /etc/profile
(D) ~/.bash_rc
9. Linux command(s) for view net port used ( )
(A) ping (B) netstat (C) lsof (D) ifconfig
10. For a distributed computing system, the following ( ) indices cannot to satisfy together
(A) consistency (B) availability (C) security (D) partition tolerance
Part III Answer Question (5 score per question)
1. There is one HelloWorld.java (has main method) which imported some classes from lib.jar.
How to compile the java file and execute the compiled class in command line?
编译:javac -Djava.ext.dirs=. HelloWorld.java
运行:java -Djava.ext.dirs=. HelloWorld
2. Please fill in blank lines to finish these codes (you can write more than 1 line in each blank line if needed):
...
// get a logger
Logger logger = xxx;
// get one connection to database
Connection conn = xxxx;
// create one transaction
Transaction tx = xxxx;
try {
_____logger.debug(“excute CRUD”);__________________________
// do some CRUD works begin
...
// do some CRUD works end
__________ tx.commit(); _____________________
} catch (Exception e) {
__________ tx.rollback();_____________________
} finally {
__________session.close();_____________________
}
...
3. We has one command "startEcho" in linux, when execute this command it will print out "hello world" to console every 30
seconds. Now we want this command to be executed in background even when I logoff linux, and all the contents it prints
out should be stored in /tmp/startEcho.log.
nohup "hello world" > /tmp/startEcho.log 2>&1 &
So how can I achieve this? (assume yourself have root account)
4. There is a Java singleton example below.
Please provide your codes to correct it for invoking the Singleton.getInstance() method in multi-thread environment with
good performance.
public class Singleton {
private static Singleton instance = null;
private Singleton() {
super();
}
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
Part IV Programming (10 score per question)
1. Write a multiple thread program to sum a big array. for example, use 5 threads to sum an integer array of 1 to 1000, one
thread sum 200 numbers.
public class MultiCalc {
private long totalResult = 5L;
private Boolean[] isCompleted = null;
public static void main(String[] args) {
(new MultiCalc()).startUp();
}
private boolean isSuccessed() {
for (int i = 0; i < isCompleted.length; i++) {
if (!isCompleted[i])
return false;
}
return true;
}
private void startUp() {
int threadNum = 5;
long numbers = 1000L;
isCompleted = new Boolean[threadNum];
for (int i = 1; i <= threadNum; i++) {
isCompleted[i - 1] = false;
Thread t = new Thread(new CalcThread(i, numbers, threadNum));
t.start();
}
synchronized (MultiCalc.this) {
try {
MultiCalc.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("计算结果为:" + totalResult);
}
class CalcThread implements Runnable {
private long start;
private long end;
private long result;
private int threadIndex;
public CalcThread(int threadIndex, long numbers, int threadNum) {
long step = numbers / threadNum;
this.threadIndex = threadIndex;
start = (threadIndex - 1) * step + 1;
if (threadIndex == threadNum) { // 是否是最后一个线程
end = numbers;
} else {
end = threadIndex * step;
}
}
@Override
public void run() {
for (long i = start; i <= end; i++) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
result += i;
}
synchronized (MultiCalc.this) {
totalResult += result;
isCompleted[this.threadIndex - 1] = true;
if (isSuccessed()) {
MultiCalc.this.notify();
}
}
}
}
}
2. Given table T below, PK is primary key, LESSON is the LESSON id in school, NAME is student name, SCORE is the
final test score of the student for the specific lesson.
(PS:1 st: sql 2 score, 2 nd sql 3 score, 3 rd sql 5 score)
1. Write a SQL to find out the student whose SCORE >= 60 for those lesson id = 3.
SELECT *FROM STUDENT WHERE SCORE >=60 AND LESSON =3
2. Write a SQL to find out the average score for each student for his all lessons;
SELECT NAME AVG(SCORE) FROM STUDENT GROUP BY NAME
3. Write a SQL to find out the student whose score is larger than the average of each lesson and sort by LESSON
(first) and NAME (second). (5 score)
SELECT LESSON NAME SCORE FROM (SELECT LESSON AVG(SCORE) A FROM STUDENT GROUP
BY LESSON),
STUDENT WHERE SCORE > A;
Part V English Writing (10 score)
Scenario:
1. Your English name is Kim.
2. You are in a team name “GoodTeam”, and the team is doing some outsource projects for customer named “IT
corporation”.
3. Your team leader is Peter, and your teammates are Elvis, Zoran, Wesley.
4. Your team has just completed an outsourcing project name “Big Bang" for “IT corporation”.
5. “Big Bang” is a customization project for “IT Customer”, who pays to “IT corporation”.
6. You find a BUG that some codes were missed to merge from A branch to B branch (“Big Bang” is done in B
branch), but it should had been done by “Henry” from “IT corporation” by 1 month before.