整型溢出 & sleep() wait() 的區別 & Java 堆排序 快速排序 計數排序

offer 110 ,109 , 預熱篇

預熱:2014年5月13日

要準備看《Effective Java》

記住啦,技術是一點一點積累的,同時在簡歷上要寫上自己會的東西,先讓簡歷變厚,再讓它變薄。

Hadoop, H2 Database Engine , Mondrian, 等,詳情參見博文:亞信聯創面試總結

反正無論做什麼都不一定能成功,我還能怎樣?只能去做但是卻不一定成功。

我想做的事情,都是有機率的,我在走的路,也是隻有機率能走下去,也許實現不了,也許最後還是會遺憾,這種感覺像是回到以往在大二的時候和杭杭參加那場演講的時候那樣,成功嗎,只是有這樣的機率,還要看你的應變。

既然無論怎樣都只是增加機率,那能增加一點是一點。

看了劉未鵬的博客,接下來的路應該這樣走(我不選擇完全按照july或者其他人的C++路來走是因爲,沒有任何一個人是可以完美複製,必須要結合自己的處境判斷。)

從博客和Github上面來增加自己獲勝的砝碼;

但是這只是他的觀點,是他覺得企業這樣可以更好的瞭解一個人,我可以將讀過的書都寫在簡歷上,但難道我所想進入的企業都會要這樣的我嗎?

我能做的其實是去了解這所企業,像當初哪位大神劉一舟一樣,上臺來不是說自己,是直接爲企業出謀劃策,要成爲企業需要的人,就要滿足企業需求,現在找找阿里招聘人員的推薦書單。

所以其實培訓機構的價值是:與學生聯繫,與企業聯繫,瞭解雙方需求,把學生培養成企業需要的人,他們就收錢,但是也許不能百分百保證這種聯繫是到位的,但是至少機率會提升很多,如果沒錢找企業去培訓,就自己去了解企業需求,至少人本身,總是最重要的。

那麼,如我所想:阿里巴巴需要怎樣的人?阿里在開拓什麼樣的業務?答案是:不知道,去找吧。

有什麼東西是,無論什麼企業都需要的?

答案1 : 數據結構和算法,無論從道聽途說還是各種面經,做後臺的人數據結構重要性不言而喻,雖然現在晚了,現在幹只能增加機率,但是比不起步好,像當初的那場演講一樣。

答案2: 數據庫,和後臺打交道不用數據庫的話就搞笑了。。。進阿里必學吧,MySQL。

答案3:編程語言Java,精通Java有多難不需要說了吧,但是要怎樣去補充Java知識?做Java認證的題目和試卷。看Java的書。

答案4:Linux,把它放在後面是因爲開發平臺也可能是windows,不過我希望進的企業必定是使用Linux的,所以要看Linux相關知識。

答案5:TCP/IP網絡協議或者是操作系統概念之類的書要看,要了解基本原理。

再思考:

答案1企業需要嗎?

答:從筆試題看無論如何都必須考,也是要掌握的,但是這是核心嗎?換言之,在排序,這個是第一位嗎?這是我的最有力砝碼嗎?答案:如果你要做編程,是的,其實排序應該換一換。

答案1 : 數據結構和算法,無論從道聽途說還是各種面經,做後臺的人數據結構重要性不言而喻,雖然現在晚了,現在幹只能增加機率,但是比不起步好,像當初的那場演講一樣。

答案2:編程語言Java,精通Java有多難不需要說了吧,但是要怎樣去補充Java知識?做Java認證的題目和試卷。看Java的書。

答案3: 數據庫,和後臺打交道不用數據庫的話就搞笑了。。。進阿里必學吧,MySQL。

答案4:Linux,把它放在後面是因爲開發平臺也可能是windows,不過我希望進的企業必定是使用Linux的,所以要看Linux相關知識。

答案5:TCP/IP網絡協議或者是操作系統概念之類的書要看,要了解基本原理。

最後一點不是不重要,也很重要,罷了,把書看了再說。

做什麼項目呢?什麼項目最能鍛鍊自己呢?

1. 我能做什麼項目

2. 企業需要怎樣的人才,企業在做什麼業務,怎麼用現有的技術實現企業正在做的業務(對某個公司來說這是極好的,也是dian哥說的對口)

3. 怎麼把我的項目和企業需求結合起來,下面就是目前我的答案。

如果我能根據現在有的他們上線的產品,猜測他們的技術,同時自己根據自己思路實現一個,這樣進入的機會不會大一點,像劉一舟一樣,站在招聘者的角度出謀劃策。

想法1:既然我的目標是阿里,是電商,就應該做一個電商的後臺。這樣纔是對口!

接下來的事情,選擇一個項目暑期主力做(也許找不到實習),這樣的情況下要了解阿里巴巴的所有的電商產品,Java後臺技術等等,從宏觀到細節。有不知道的問問偉鋮,不過偉鋮不是做後臺的。

要點1:數據庫檢索角度

要點2:想google或者百度這種打一個字就彈出來很多搜索條目的情況是

要點3:阿里非常重視大數據,因爲數據的確是大,天池大數據平臺

要點4:阿里集羣,深入剖析阿里巴巴雲梯YARN集羣


第一天:2014年5月14日

好吧孩子,今天真的真的非常熱,同時沒有收到UC的筆試通知晚上去霸面UC可能沒去小測試感到遺憾,怎麼辦,怎麼做?

不要放棄啊孩子,可以試試從錢方面着手,先就業再擇業,數據結構和算法是爲了擇業做打算,但是Java基礎和框架的精通是爲了就業做打算,還有在教授那裏拿到的如果有可以作爲未來3個月找不到實習養活自己的錢(還是再找找吧),可以考慮下做個屬於自己的校園網的項目,比什麼都不做好,其實這兩天就是在糾結着應該做什麼項目,做什麼項目有意義和價值。像順平老師那樣做個校園網頁不錯,至少算是電商類的,而且是oracle數據庫。加油啊,即使事情再虐,也不要放棄。

今天看了知乎上面的一片精彩的文章,裏面提到IT互聯網的10個等級。

在這篇文章裏面還可以看得內容是:連紅黑樹或者算法導論都沒看過的人,真心不配做後臺。。。

所以事實上,該做什麼項目這一點還是沒有定下來。

這個,可以在對阿里多一點了解以後,在6月份再開始,很不甘心,但也是沒辦法的。看書,搞掂現在手頭上的項目,加油~~


第二天:2014年5月15日

日子總是過得很快,昨天夜晚去了UC筆試,霸筆成功了,同時覺得簡歷還應該修改一些東西。

UC的筆試題,不會的回憶如下:

1. Integer.MAX_VALUE

int a = Integer.MAX_VALUE;
long b =a+1 ;
printBinaryLong("long b",b);
printBinaryInt("int a+1",a+1);
printBinaryLong 和 printBinaryInt是自定義函數,完整代碼如下:

public class template{
	public static void main(String[] args){
		test();
	}

	static void test()
	{
	
		// printBinaryInt("int a",a);
		int d = 2147483647;
		// printBinaryInt("int d",d);
		int c = Integer.MIN_VALUE;
		// printBinaryInt("int c",c);
		int a = Integer.MAX_VALUE;
		long b =a+1 ;
		printBinaryLong("long b",b);
		printBinaryInt("int a+1",a+1);



	}

	static void printBinaryInt(String s, int in){
		System.out.println(s+", int: "+in+", binaryy: ");
		System.out.print("  ");
		for(int i=31; i>=0;i--){
			if( ( (1<< i)& in)!=0)
				{System.out.print("1");}
			else{
				System.out.print("0");
			}	
				
		}
		System.out.println();
	}

	static void printBinaryLong(String s, long l){
		System.out.println(s+", long: "+l+", binaryy: ");
		System.out.print("  ");
		for(int i=63; i>=0;i--){
			if( ( (1L<< i)& l)!=0)
				{System.out.print("1");}
			else{
				System.out.print("0");
			}	
				
		}
		System.out.println();
	}

}

由此可見,過程是:a = Integer.MAX_VALUE , a+1 發生溢出

注意二進制表示的變化,011111111111111111111111111(大概如此)

          變成 10000000000000000000000000 成爲了Integer.MIN_VALUE,然後這個值賦予給b

b是能接受這個值的,同時保持值不變的情況下進行符號位拓展,成爲了 33個1和31個0 的二進制表示。

2. 

線程間的通訊方式:


以上是linux中的。

3. Thread中的sleep()和wait()的方式區別

sleep()在 Java SE 7 文檔中的解釋:

sleep是在java.lang.Thread中的

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.

wait()的

wait()是在java.lang.object中的

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

他們兩最大的區別是sleep沒有釋放線程鎖,wait釋放了,這篇博文有簡單描述,只是簡單理解,裏面的內容有些不準確,還是應該查看Java SE API

4. Hashtable 和 HashMap的區別之完整答案:

1). 線程安全和飛線程安全

2). Hashtable不允許null(key和value都不可以),HashMap可以(key和value都可以)

他們的區別大概有6個,詳情見以下博文

5. Vector和ArrayList的去區別(全都考容器類)

1). 線程安全與非線程安全

2). vector提供 indexof接口,

Returns the index of the first occurrence of the specified element in this vector, or -1 if this vector does not contain the element.

3). 當capacity不夠的時候,vector增加100% ,ArrayList增加50%+1

6. 如果要你設計一個手機遊戲網站下載站點,設計那些功能引用戶(上 a.9game.cn 看一看)

1) 熱門遊戲

2)新遊推薦

3)網遊排行

4)飆升最快

5)熱門分類

6)特色集合

7. 空指針的問題

		int[] A = new int[8];
		System.out.println(A.equals(0));
輸出:false 

A裏面已經全部初始化爲0

8. do-while和while-do的唯一區別是:do-while無論如何都會執行一次,其餘都一樣,看下面代碼:

		int a =-1 ;
		do{
			a = a-1;
			System.out.println("do-while:"+a);
		}while(a>0);

		while(a>0){
			a = a-1;
			System.out.println("while-do:"+a);
		}
輸出爲:do-while:-2



程序員必讀文章10篇


下面給出Java的一個堆排序:

import java.util.*;

public class template{
	public static void main(String[] args){
		System.out.println(Arrays.toString(A));
		HeapSort(A);

	}


	static int[] A = {0,5 , 7 , 8 , 9 ,10 ,11,2 ,0 ,1};	

	static int heap_size = 0;

	static int Left(int i){
		return 2*i;
	}

	static int Right(int i){
		return 2*i+1;
	}

	static void MaxHeapify(int[] A, int i){
		int l = Left(i);
		int r = Right(i);
		int largest = 0;
		if(l<=heap_size && A[l]>A[i]){
			largest = l;
		}
		else{
			largest = i;
		}
		if(r<=heap_size && A[r]>A[largest]){
			largest = r;
		}
		if(largest != i){
			Swap(A,i,largest);
			MaxHeapify(A,largest);
		}
	}

	static void BuildHeap(int[] A){
		heap_size = A.length-1;
		for(int i=(A.length-1)/2;i>=1;i--){
			// System.out.println("BuildHeap:"+i);
			MaxHeapify(A,i);
		}
	} 

	static void HeapSort(int[] A){
		
		BuildHeap(A);
		System.out.print("(");
		for(int i=A.length-1;i>=2;i--){
			Output(A,1);
			Swap(A,1,i);
			heap_size--;
			MaxHeapify(A,1);
		}
		System.out.print(A[1]);
		System.out.print(")");
	}

	static void Output(int[] A, int i){
		System.out.print(A[i]+",");
	}

	static void Swap(int[] A,int a, int b){
		// System.out.println("swap:"+a);
		// System.out.println("swap:"+b);
		int temp = A[a];
		A[a] = A[b];
		A[b] = temp;
	}


	

	

}

下面給出Java的快速排序:(使用了尾遞歸)

import java.util.*;
public class QuickSort{
	public static void main(String[] args){
		int[] A = {5 , 7 , 8 , 9 ,10 ,11,2 ,0 ,1};
		quickSor(A,0,A.length-1); 
		System.out.println(Arrays.toString(A));
	}

	static void quickSor(int[] A,int begin, int end){
		int p=0;
		while(begin<end){
			p=Partition(A,begin,end);
			quickSor(A,p+1,end);
			end = p-1;
		}
	}

	static int Partition(int[] A,int begin, int end){
		int compare = A[end];
		int i = begin-1;
		for(int j= begin;j<=end-1;j++){
			if(A[j]>=compare){
				// i++;
				Swap(A,++i,j);
			}
		}
		Swap(A,i+1,end);
		return i+1;
	}

	static void Swap(int[] A, int a , int b){
		int temp = A[a] ;
		A[a] = A[b];
		A[b] = temp;
	}





}

下面給出計數排序(穩定排序)

import java.util.Arrays;
public class court_sort{
	public static void main(String[] args){
		int[] A = {5,2,4,5,9,10,7,1,0,9,2};
		int k = max(A);
		int[] B = new int[A.length];
		CountSort(A,B,k);
		System.out.println(Arrays.toString(A));
		System.out.println(Arrays.toString(B));
	}

	static int max(int[] A){
		int maxV = 0;
		for(int a : A){
			if(a>maxV)   maxV = a;
		}
		return maxV+1;
	}

	static void CountSort(int[] A, int[] B, int k){
		int[] C = new int[k];
		for(int i=0;i<C.length;i++){
			C[i] =0;
		}
		for(int j=1;j<A.length;j++){
			C[A[j]]++;
		}
		for(int i=1;i<C.length;i++){
			C[i] = C[i]+C[i-1];
		}
		for(int j=A.length-1;j>=1;j--){
			B[C[A[j]]] = A[j];
			C[A[j]]--;
		}
	}

	

}






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章