转另一个论坛的帖子:迅雷面试回来,用了整整一下午(不知道怎么说了,其中等待时间都快2小时了),自己感觉笔试和上机还可以,但技术面谈这一关答得不太好,现在再次感觉互联网公司与一般软件公司的区别了,其中一点就是互联网应用在性能上要求很高,谈了一个小时大部分题目感觉都在谈论性能问题,自己在方面一直是弱项,汗啊:( 仔细回忆了一下整个面试过程的题目,记录下来,希望大家多多给点意见讨论下啊 一、笔试题:
A)JAVA基础多项选择题,比较简单,略 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的,说出实现原理? 期待大家的探讨,共同提高,多谢
A)JAVA基础多项选择题,比较简单,略 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的,说出实现原理? 期待大家的探讨,共同提高,多谢
对这个问题十分感兴趣:
mvc原理,mvc模式的优缺点,如果让你设计你会怎么改造MVC? 麻烦大牛们发表点意见
这里应该问hashMap的原理才对吧?单纯的map只是一个接口,各种不同的实现类采用的算法可能不一样。8、描术算法,如何有效合并两个文件:一个是1亿条的用户基本信息,另一个是用户每天看电影连续剧等的记录,5000万条。内存只有1G???
这个有点意思,等大牛来讲。1亿条用户信息,那文件得多大了?9、在1亿条用户记录里,如何快速查询统计出看了5个电影以上的用户?
建索引。
Java上机实现统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数?
/*文本内容仅限数字,字母,及空格*/
import java.io.*;
class Ex6_5 {
public static void main ( String[] args ) {
String fileName = "C:/Hello.txt" , line;
int i,j,f,k;
try {
BufferedReader in = new BufferedReader(
new FileReader( fileName ) );
line = in.readLine(); //读取一行内容
while ( line != null ) {
if(Character.isLetter(line))
i++;
else if(Character.isDigit(line))
j++;
else
f++;
line = in.readLine();
k++
}
in.close();
System.out.println("字母"+i+"数字"+j+"空格"+j+"行数"+k)
}
catch ( IOException iox ) {
System.out.println("Problem reading " + fileName );
}
}
}对于这个算法题很感兴趣,期待高手作答
2)假如有字符串“6sabcsssfsfs33” ,用最有快速的方法去掉字符“ab3”,不能用java内置字符串方法(indeOf,substring,replaceAll等)?
import java.io.*;
class Ex6_5 {
public static void main ( String[] args ) {
String fileName = "C:/Hello.txt" , line;
int i,j,f,k;
BufferedReader in = new BufferedReader(
new FileReader( fileName ) );
line = in.readLine(); //读取一行内容
while ( line != null ) {
int cU = 0 ;
int cL = 0 ;
int cN = 0 ;
char c ;
for(int i=0 ;i<line.length() ;i++) {
c = s.charAt(i) ;
if(c > 'a' && c < 'z') {
cL ++ ;
}
else if(c > 'A' && c < 'Z') {
cU ++ ;
}
else {
cN ++ ;
}
line = in.readLine();
k++ ;
}
System.out.println("Number of LowerCase:" + cL) ;
System.out.println("Number of UpperCase:" + cU) ;
System.out.println("Number of NotChar:" + cN) ;
}
写错了,在更正一下
public class ThreadTest extends Thread { public void run() {
for (int i = 0; i < 10; i++) {
System.out.print(this.getName());
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} public static void main(String[] args) throws InterruptedException {
ThreadTest a = new ThreadTest();
a.setName("A");
ThreadTest b = new ThreadTest();
b.setName("B");
ThreadTest c = new ThreadTest();
c.setName("C");
a.start();
b.start();
c.start();
}
}
主存是1*1024*1024*1024字节,设为M
记录占用R字节。填满内存须要M/B次,一个块用于临时交互,那么一次可以为M/B-1个快集合填充。得出B/R等于多少?用这个值进行划分记录。大约出现N个有限集合。最后使用归并算法对N个集合进行归并。使用两趟归并算法就是TB数据集。基本够用。说简单,实现也要一段时间,参考数据库大型算法中的多路归并就解决了。9、在1亿条用户记录里,如何快速查询统计出看了5个电影以上的用户?这个问题意义不大:没有关系结构,电影重复看算不算5个?但是关系中count和用户信息都在一个临时记录中这倒是真的。
for(int i=0; i<1000; i++ ) {
System.out.print(Thread.currentThread().getName());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} public static void main(String[] args) throws InterruptedException {
testThread a = new testThread();
testThread b = new testThread();
testThread c = new testThread();
Thread ta = new Thread(a);
ta.setName("A");
Thread tb = new Thread(c);
tb.setName("B");
Thread tc = new Thread(b);
tc.setName("C");
ta.start();
Thread.sleep(50);
tb.start();
Thread.sleep(50);
tc.start();
}}
for(int i=0;i<charNum.length;i++)
{
if('a'==charNum[i] || 'b'==charNum[i] || '3'==charNum[i])
{
char []temp=new char[charNum.length-2];
for(int j=0;j<i;j++)
{
temp[j]=charNum[j];
}
for(int j=i+1;j<charNum.length;j++)
{
if(j!=charNum.length-1)
{
temp[j-1]=charNum[j];
}
}
charNum=temp;
i--;
continue;
}
}
我感觉这这里哪怕是执行100次,1000次都可以的.CPU的时间片肯定比执行3条打印语句所花的时间要大,那么在每个for循环里面的动作都不可能被时间片的切换都打断,故而每次睡眠后都能够及时的按照优先级打印,顺序不会紊乱,我试过1000次都没有出错.但是要注意一点就是睡眠时间一定要大于3次执行的打印语句.
我试过把睡眠时间控制在500以上不管多少次打印顺序都不会出错,但是如果时间在500以下就很容易出现打印顺序不稳定的现象,这个时候就如楼上所说的出现不稳定的现象。更多的关于多线程的理论比较复杂期待高手深入讨论,祝楼主好运.
package com.saturday;public class KMP {
public static String myReplaceAll(
String input,
String replaced){
//短路掉不可能匹配的情况
if(replaced.equals("")
||input.length()<replaced.length()){
return input;
}
StringBuffer buf=new StringBuffer();
char[] s=input.toCharArray();
char[] r=replaced.toCharArray();
int rLen=r.length;
int matchCount;
for(int i=0,sLen=s.length;i<sLen;){
if(i<sLen-rLen){
//检查匹配
matchCount=0;
for(int j=0;j<rLen;j++){
if(s[i+j]==r[j]){
matchCount++;
}else{
break;
}
}
//完全匹配
if(matchCount==rLen){
i+=rLen;
continue;
}
//部分匹配
if(matchCount>0){
for(int j=0;j<matchCount;j++){
buf.append(s[i++]);
}
continue;
}
}
buf.append(s[i++]);
}
return buf.toString();
}
public static void main(String[] args){
String input="123 mfc mf fc mfdC mfmfc cmfc dd abc";
String replaced="1234";
System.out.println(
myReplaceAll(input,replaced).equals(input.replaceAll(replaced,""))
);
}
}from
http://topic.csdn.net/u/20091130/23/79caaaa8-fb36-4dc4-a23a-13e816a28329.html?seed=653129929&r=61557319#r_61557319
不是说不准用String的内置函数吗?要是这么做,有谁不会做?
1、计算机、软件、通讯等相关专业;
2、本科2年以上JAVA开发经验, 硕士1年以上相关经验;
3、能够掌握当前主流的J2EE开发框架中的一种,或者熟悉ORACLE等大型关系数据库;
4、工作地:深圳。
如有意愿,请把简历发送到:[email protected].
欢迎来信咨询,有信必复!
薪水上不封顶,只要能力强,开多少都可以满足!
职位:系统分析,架构设计,高级程序员,程序员,数据库开发人员,软件测试等。
private int i=1;
public synchronized void run()
{
while(i<=30)
{
if(i%3==0)
{
System.out.print(Thread.currentThread().getName());
i++;
try {
this.wait(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.notify();
}
if(i%3==1)
{
System.out.print(Thread.currentThread().getName());
i++;
try {
this.wait(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.notify();
}
else
{
System.out.print(Thread.currentThread().getName());
i++;
try{this.wait(100);}
catch(InterruptedException e)
{
e.printStackTrace();
}
this.notify();
}
}
}
public static void main(String[] args) {
TestABC t=new TestABC();
Thread th=new Thread(t);
th.setName("A");
th.start();
Thread th1=new Thread(t);
th1.setName("B");
th1.start();
Thread th2=new Thread(t);
th2.setName("C");
th2.start();
}}
public class TestABC implements Runnable{
private int i=1;
public synchronized void run()
{
while(i<=30)
{
if(i%3==0)
{
System.out.print(Thread.currentThread().getName());
i++;
try {
this.wait(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.notify();
}
if(i%3==1)
{
System.out.print(Thread.currentThread().getName());
i++;
try {
this.wait(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.notify();
}
else
{
System.out.print(Thread.currentThread().getName());
i++;
try{this.wait(100);}
catch(InterruptedException e)
{
e.printStackTrace();
}
this.notify();
}
}
}
public static void main(String[] args) {
TestABC t=new TestABC();
Thread th=new Thread(t);
th.setName("A");
th.start();
Thread th1=new Thread(t);
th1.setName("B");
th1.start();
Thread th2=new Thread(t);
th2.setName("C");
th2.start();
}}
结果是ABCABCABCABCABCABCABCABCABCABC
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Myreplace.myReplaceAll("abcdefghhhhcedcdehabchhhh", "cde","!");
}
public static String myReplaceAll(String input,String regx,String rep)
{
// 特殊情况判断 char i [] = input.toCharArray();
char r [] = regx.toCharArray();
StringBuffer buf = new StringBuffer();
boolean b = false;
for(int k=0;k<i.length;k++)
{
if(i.length-r.length>0)
{
for(int j=0;j<r.length;j++)
{
System.out.println(i[k+j]+"是否匹配"+r[j]);
if(i[k+j]==r[j])
{
b=true;
}
else
{
b=false;
break;
}
}
}
if(b)
{
k+=regx.length()-1;
buf.append(rep);
}else
{
buf.append(i[k]);
}
}
System.out.println(input);
System.out.println(buf);
System.out.println(input.replace(regx, rep));
return input;
}}
/*
*******************************************************************************
* Operation.java
*
*<项目内容>
* 项目名 : ThreeThreads
*<类名>
* Operation
*<功能概要>
*
*<更新履历>
* 日期 版本 作成者 描述
* 2009-12-3 1.00 yanfengg 新规做成
*******************************************************************************
*/
package com.icyy.test;/**
* <p>
* [概 要]
* 描述一個操作的接口
* [详 细]
*
* [备 考]
*
* [环 境] J2SE 1.5
* </p>
*
* @author Sidney Yang
* @version 1.0
*/
public interface Operation { // 要執行的操作
public void run();
}/*
*******************************************************************************
* Abc.java
*
*<项目内容>
* 项目名 : ThreeThreads
*<类名>
* Abc
*<功能概要>
*
*<更新履历>
* 日期 版本 作成者 描述
* 2009-12-3 1.00 Sidney Yang 新规做成
*******************************************************************************
*/package com.icyy.test;
import java.util.ArrayList;
import java.util.List;/**
* <p>
* [概 要]
* 將一系列操作分配給不同的線程并重複同步依次執行這些線程(操作)直到滿足退出條件。
* [详 细]
*
* [备 考]
*
* [环 境] J2SE 1.5
* </p>
*
* @author Sidney Yang
* @version 1.0
*/
public class Abc{
// 用於存放所有線程的list.
private List<ThreadsWithOperation> operArray = new ArrayList<ThreadsWithOperation>();
// 線程計數器,每有一個線程被執行,自增1.
private int threadCounter = 0; // 添加一個帶操作的線程
public void push(Operation oper){
operArray.add(new ThreadsWithOperation(oper));
}
// 啟動所有線程
public void start(){
for(ThreadsWithOperation thread : operArray){
thread.start();
}
}
/**
* 帶操作的線程類
* @author Sidney Yang
* @version 1.0
*/
class ThreadsWithOperation extends Thread{
// 表示一個操作的對象。
private Operation oper; /**
* 用一個Operation得對象構造一個ThreadsWithOperation
* Constructors ThreadsWithOperation
* @param oper 表示一個操作的對象
*/
ThreadsWithOperation(Operation oper){
this.oper = oper;
}
/**
* 線程方法。執行流程為:
* 1.判斷是否輪到本線程執行,若不是,則跳到3步驟。
* 2.執行Operation對象里的操作,并將執行權移交給下一個線程。
* 3.喚醒所有等待線程并判斷是否滿足退出條件,如果不滿足則跳到步驟5。
* 4.將自己加入等待隊列。
* 5.結束
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @see java.lang.Thread#run()
*
*/
@Override
public void run(){
while(!Abc.this.readyToQuit()){
synchronized(Abc.this){
if(isMyTurn()){
oper.run();
turnNext();
}
Abc.this.notifyAll();
if(!Abc.this.readyToQuit()){
try {
Abc.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
/**
*
* 判斷是否輪到本線程執行
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @return 如果輪到本線程執行返回true,否則返回false
*
*/
private boolean isMyTurn(){
int threadIndex = Abc.this.operArray.indexOf(this);
return Abc.this.threadCounter % Abc.this.operArray.size() == threadIndex;
}
/**
*
* 將執行權交給下一個線程
*
* @Create Date: 2009-12-3
* @author Sidney Yang
*
*/
protected void turnNext(){
Abc.this.threadCounter++;
}
}
/**
*
* 此方法給出所有線程退出的條件,若返回true則所有線程結束,子類應根據情況重寫此方法。
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @return 若滿足線程結束條件返回true,否則返回false.
*
*/
protected boolean readyToQuit() {
return false;
}
/**
*
* 返回線程計數器
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @return 線程計數器的值
*
*/
public int getThreadCounter(){
return threadCounter;
}
/**
*
* 測試用main方法
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @param args 控制臺傳入的參數
*
*/
public static void main(String[] args){
Abc abc = new Abc(){ /**
* 重寫readyToQuit方法使3個線程各執行10次。
*
* @Create Date: 2009-12-3
* @author Sidney Yang
* @return 若滿足線程結束條件返回true,否則返回false.
* @see com.icyy.test.Abc#readyToQuit()
*
*/
@Override
public boolean readyToQuit() {
return this.getThreadCounter() >= 30;
}
};
abc.push(new Operation(){
public void run() {
System.out.print("A");
}
});
abc.push(new Operation(){
public void run() {
System.out.print("B");
}
});
abc.push(new Operation(){
public void run() {
System.out.print("C");
}
});
abc.start();
}
}
粗略寫了一下,沒有完善,應該能滿足要求。
ABCABCABCABCABCABCABCABCBACABC
多运行几遍,可能结果会不同,但是这个证明了一个问题就是可能会出现问题。。
顺便BS下fanmaomao的为人,我写东西就是来探讨问题的,我说不对难道还有错了,难道我知道不对也不说?垃圾人品。