最近面试很头疼,因为满以为自己工作了1年多了,实际coding经验却压缩到不到1年。每每被面试官“痛扁”,心里特别不痛快,总以为我能给你交活不就完了吗有必要在基础上为难我吗!相信大多数不会总结,在面试中屡屡受挫的小伙伴你也是差不多的吧。因为没有一份漂亮的能拿得出手说得出口的简历,所以打好基础是非常必要的。不要再说‘我能给你完成工作就行了’这样的话了,在面试官看来你连基础都做不好,他很怀疑你交付的任务结果的质量。除此之外,他还会对你的学习研究能力进行怀疑,因此你首先就被pass掉了,就不要想着跟对方谈薪资了。
哈哈哈哈。。。。。进入正题
下面分享一些笔试题,至今还在用来面试的,稍后还会做补充。
1、面试题:有3个线程ID分别是a,b,c,请用多线程实现,在屏幕上循环打印10次abc
据说这是迅雷10年的笔试题了。算是经典吧,经典必须看。
package test.thread;
public class TestThread {
public static void main(String[] args) {
for(int i = 0; i < 10; i++){
try {
Thread a = new Thread(new Runner("A"));
a.start();
a.join();
Thread b = new Thread(new Runner("B"));
b.start();
b.join();
Thread c = new Thread(new Runner("C"));
c.start();
c.join();
System.out.println();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Runner implements Runnable{
private String name;
public Runner(String name){
this.name = name;
}
public void run(){
System.out.print(name);
}
}
小结:当我拿到这份笔试题时,我觉得无从下手,本来就线程只是薄弱的我抓耳挠腮,还想着抄网上的。这道题竟然这么简单的就被解决了,汗颜!线程知识中,一定要记住理解线程的4个状态,理解了这4个状态组成的状态装换图,再解决实际问题就好多了。重在理解。
2、面试题:统计某一目录下每个文件出现的字母数、数字个数、空格个数及行数
package test.file;
public class file {
private String name; //文件名
private int letterNum;//字母数
private int number;//数字数
private int lineNum;//行数
private int whitespaceNum;//空格数
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLetterNum() {
return letterNum;
}
public void setLetterNum(int letterNum) {
this.letterNum = letterNum;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public int getLineNum() {
return lineNum;
}
public void setLineNum(int lineNum) {
this.lineNum = lineNum;
}
public int getWhitespaceNum() {
return whitespaceNum;
}
public void setWhitespaceNum(int whitespaceNum) {
this.whitespaceNum = whitespaceNum;
}
}
package test.file;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FileTest {
public static List<file> fileList = new ArrayList<file>();
public static void getFile(String path){
File file = new File(path);
System.out.println(file.getName());
computeFile(file);
}
//方法1:
public static void computeFile(File fileDir){
if(fileDir.isDirectory()){
File[] fileArray = fileDir.listFiles();
for(File f : fileArray){
if(f.isDirectory()){
computeFile(f);
} else {
try {
int ch = 0;
int count = 0; //数字
int j = 0; //字母
int i = 0; // 行数
int k = 0; // 空格
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new FileReader(f));
while((ch = fis.read()) != -1){ //读取一个字节,-1代表文件末尾
if(ch >='0' && ch <='9'){
count++;
}
if((ch >= 'a' && ch <= 'z') || (ch >= 'A'&& ch <= 'Z')){
j++;
}
if(ch == ' '){
k++;
}
}
while(br.readLine() != null){
i++;
}
file fi = new file();
fi.setName(f.getName());
fi.setLetterNum(j);
fi.setNumber(count);
fi.setWhitespaceNum(k);
fi.setLineNum(i);
fileList.add(fi);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
//打印输出
public static void print(){
for(file f : fileList){
System.out.println(f.getName() + ": 数字:" + f.getNumber()
+ " ,字母:" + f.getLetterNum() + " ,行数:" + f.getLineNum()
+ " ,空格:" + f.getWhitespaceNum());
}
}
public static void main(String[] args) {
getFile("G://temp");
print();
}
}
小结:这道题其实也不难。考察文件的I/O操作。File类的常用方法,以面向对象的方式解答出来能够更好的体现你对java的学习程度。
3 实现一个算法,确定一个字符串的所有字符是否全都不同。假使不允许使用额外的数据结构,又该如何处理?
先问清楚是ASCII字符集还是Unicode字符串。假如这里题目中是指ASCII字符集的话,因为ASCII字符集有256个字符。
public boolean isUniqueChars2(String str){
if(str.length > 256){
return false;
}
boolean[] char_set = new boolean[256];
for(int i=0; i < str.length; i++){
int val = str.charAt(i);
if(char_set[val]){
return false;
}
char_set[val] = true;
}
return true;
}
另附其他迅雷笔试题
B)问答:
1)ajax原理、如何实现刷新数据及优点?
2)门面模式的解释、适用场合?
3)写6个linux常用命令?
4)SQL语句题,较简单
C)编程:
1)有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…
2)假如有字符串“6sabcsssfsfs33” ,用最有快速的方法去掉字符“ab3”,不能用java内置字符串方法(indeOf,substring,replaceAll等)?
二、上机题:
Java上机实现统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数?
三、面试题:
1、说说JVM原理?内存泄露与溢出区别,何时产生内存泄露?
2、用java怎么实现有每天有1亿条记录的DB存储?mysql上亿记录数据量的数据库如何设计?
3、mysql支持事务吗?DB存储引擎有哪些?
4、mvc原理,mvc模式的优缺点,如果让你设计你会怎么改造MVC?
5、hibernate支持集群吗?如何实现集群?
6、tomcat 最多支持并发多少用户?
7、map原理,它是如何快速查找key的?map与set区别?
8、描术算法,如何有效合并两个文件:一个是1亿条的用户基本信息,另一个是用户每天看电影连续剧等的记录,5000万条。内存只有1G???
9、在1亿条用户记录里,如何快速查询统计出看了5个电影以上的用户?
10、Spring如何实现IOC与AOP的,说出实现原理?