今天下午參加了平安科技的見面會之後,晚上接着參加了微衆銀行的線下筆試。這樣一天下來,其實挺累的。現在記錄一下今天的一些心得體會。
平安科技見面會上一個搞技術開發的工作人員在分享經驗時問了兩個問題,讓我記憶猶新。
問題1:如果你有一個好的idea,你會怎麼做?假如你是公司的一個員工。
當時,我沒太明白他的意思,後來經過他的提示後,才知道他問的是軟件開發流程。
首先,有了一個好的idea,要做市場調研和可行性分析。這樣才能從老闆或者投資方那裏拿錢。
然後呢,對於產品經理,需要做需求分析,給出產品原型。緊接着,項目經理需要給出項目的解決方案,比如開發中的人員分配。
再接着,就是架構師出場,他需要做架構設計以及數據庫設計,同時進行技術選型。
接下來的事情就好辦了,編程,測試,上線,運維等
問題2:以下單例類如何改進?
public class Singleton {
private Object instance = null;
public Singleton(){}
public Object getInstance(Object object){
if(instance == null){
instance = new Object();
}
return instance;
}
}
在getInstance方法前加上synchronized關鍵字。因爲當併發量比較大時,有可能兩個線程同時訪問該對象,此時可能創建兩個單例對象。因此需要做同步處理
接下來在說一說微衆銀行的面試題:
第一題:寫出1....N之和的函數,時間複雜度o(1)
答:利用等差數列公式,Sn = n*(n+1)/2;
第二題:求兩個數中的較大者,該數可以是int,float,double,byte類型
答:構造泛型類
第三題:生產者消費者隊列:三個生產者,兩個消費者。
package yy;
public class ProduceConsume {
public static void main(String[] args) {
SysStack sysStack = new SysStack();
Producer producer = new Producer(sysStack);
Consume consume = new Consume(sysStack);
Thread tp = new Thread(producer);
Thread tc = new Thread(consume);
tp.start();
tc.start();
}
}
class SteamBread{
int id;//饅頭編號
public SteamBread(int id) {
this.id = id;
}
public String toString(){
return "steamBread:"+id;
}
}
class SysStack{
int index = 0;
SteamBread[] stBreads = new SteamBread[6];
//放入框中,相當於入棧
public synchronized void push(SteamBread sb){
while(index == stBreads.length){//棧滿
try{
this.wait();//讓當前線程等待
}catch(InterruptedException e){
e.printStackTrace();
}
}
this.notify();//喚醒在此對象監視上等待的單個線程,即消費者線程
stBreads[index]=sb;
this.index++;
}
//從框中拿出,相當於出棧
public synchronized SteamBread pop(){
while(index == 0){//棧空
try {
this.wait();//阻塞
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.notify();//喚醒
this.index--;
return stBreads[index];
}
}
class Consume implements Runnable{
SysStack sysStack = null;
public Consume(SysStack ss){
super();
this.sysStack = ss;
}
public void run(){
for(int i=0; i<20; i++){//開始消費饅頭
SteamBread steamBread = sysStack.pop();
System.out.println("消費了"+steamBread);
try{
Thread.sleep(100);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
class Producer implements Runnable{
SysStack sysStack = null;
public Producer(SysStack ss) {
this.sysStack = ss;
}
@Override
public void run() {
//開始生產饅頭
for(int i=0;i<20;i++){
SteamBread steamBread = new SteamBread(i);
sysStack.push(steamBread);
System.out.println("生產了"+steamBread);
try {
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
第四題:假設QQ號碼爲int型,如何快速查看某QQ號是否已經被註冊