曾經(jīng)數(shù)次導(dǎo)演編程語(yǔ)言PK的CSDN,今天又發(fā)表了篇很娛樂(lè)很有導(dǎo)火索的文章
實(shí)例演示:Java和C語(yǔ)言哪個(gè)更快?
作者很娛樂(lè)地寫(xiě)了堆代碼來(lái)驗(yàn)證Java不比C語(yǔ)言快,留言的高手們也很娛樂(lè)地來(lái)繼續(xù)聲討。孰是孰非我也不關(guān)心,Java和C的快慢以前也層寫(xiě)過(guò)一些所謂的計(jì)算程序比較過(guò),JVM的Hostspot機(jī)制,在這種小打小鬧的“測(cè)試”下確實(shí)威力巨大。有時(shí)還真的會(huì)比完成相同計(jì)算任務(wù)的C程序快。但是不要忘了真刀真槍的環(huán)境,大型應(yīng)用光一個(gè)GC就足可讓Java落后C寫(xiě)的本地代碼一大截!
無(wú)聊無(wú)聊
高級(jí)接口封裝變成了底層接口,需求幾天之內(nèi)就能完全變個(gè)樣,真是奇跡!
剩下一個(gè)月不到了,咬咬牙,邊干活邊寫(xiě)論文吧。
Dido這幾天也很累,每天短信哄她睡覺(jué),很讓人心疼的女孩兒。
口袋里僅剩下20塊零五毛的時(shí)候,突然發(fā)現(xiàn)了錢的重要。
于是給人做了兩個(gè)小程序,前后總共大概花了三天,拿了1000塊到手。學(xué)院還欠自己600塊的項(xiàng)目補(bǔ)助。不知道何時(shí)才能到賬上。一向不愿意計(jì)算口袋里的錢,這回終于窘迫起來(lái)。
賺了點(diǎn)小米,畢業(yè)還有一個(gè)月不到,先撐過(guò)去。晚上和人吃飯,笑談一個(gè)局域網(wǎng)流量計(jì)費(fèi)的活兒。開(kāi)玩笑說(shuō)一周時(shí)間,優(yōu)惠價(jià)2000。怕要真有活兒,一周時(shí)間搞不定吧。說(shuō)大話容易,做起來(lái)是另外回事。Dido說(shuō)我有時(shí)喜歡說(shuō)大話,我承認(rèn)。
論文寫(xiě)了七千字,繼續(xù)努力。
上海,我來(lái)了。雖然第一份工作并沒(méi)有想象中的好,但是,會(huì)硬著頭皮撐下去。生活給的是挑戰(zhàn),喜歡挑戰(zhàn)。
? 631所的項(xiàng)目已經(jīng)開(kāi)始了兩個(gè)月了.現(xiàn)在還是在做運(yùn)行代理這一模塊.我算是搞核心編碼吧.被JNI,Socket,Thread,RMI整得暈乎著呢.
? 沒(méi)有考試壓力,沒(méi)有就業(yè)壓力.一切都平靜得很.每天睡六小時(shí).兩杯咖啡(早晨中午各一杯).三天一包煙.中午是兩節(jié)玉米外加一大片菠蘿.兩天BT一部電影.
?? 一天上班7個(gè)半小時(shí),晚上看書(shū)3小時(shí).喜歡現(xiàn)在的寧?kù)o.寧?kù)o得如水一樣.
? 三方協(xié)議寄出去了,沒(méi)正式回到手里,學(xué)院沒(méi)蓋章之前,還是有些小小的不放心.^_^,畢竟回上海的機(jī)會(huì)太難得了.
上海不是我家,可對(duì)我而言,對(duì)于一個(gè)遠(yuǎn)在西北求學(xué)的人而言,至少是家門口了那天打電話告訴媽媽,聽(tīng)得出來(lái),她非常高興.
現(xiàn)在才發(fā)現(xiàn)自己沒(méi)有想象中那么豁達(dá),以為很多事情能放得開(kāi).以為天下之大,到處可以容身.是的,天下是很大,可是我能容身的地方卻不是如此.總有張網(wǎng),心里一張網(wǎng)把我網(wǎng)住. 記得有人說(shuō)過(guò),牢籠是自己造的. 很有道理,但是我卻愿意囚禁在這籠子里.
一片沒(méi)邊際的天,有幾個(gè)人真正敢去接受?
打定主意回去,未來(lái)怎么樣,我沒(méi)法去想. 最起碼,回去,能給未來(lái)一個(gè)模糊可能性,我的要求不高.知足了.
看著辦吧,一切都如田野里的百合,自然就會(huì)開(kāi)的.
我所要做的,只是去呼吸,去汲取,去曬太陽(yáng)! 今天開(kāi)始復(fù)習(xí)專業(yè)課,無(wú)聊的宣講會(huì)或招聘會(huì)一律不參加!
編程求解: 運(yùn)動(dòng)員打靶,10發(fā)子彈命中90環(huán)(每分成績(jī)?yōu)?到10環(huán)不等)
???????????????? 求可能情況的總數(shù)
解法一:
?#include <stdio.h>
#include <stdlib.h>
int f(int n, int m)
{
?int fn=0,i;
?if(m<0||m>10*n) return 0;
?if(n==1) return 1;
?for(i=0;i<=10;i++)
?fn+=f(n-1,m-i);
?return fn;
}
int main()
{
?int n,m;
?printf("Please enter n and m:");
?scanf("%d%d",&n,&m);
?printf("\n%d發(fā)打中%d環(huán)有%d種可能.\n",n,m,f(n,m));
?system("PAUSE");
?return 0;
}?
解法二:
?#include"stdio.h"
int main(){
int num =1,i;
for(i=1;i<=10;i++)
num = num *(9+i)/i;
printf("%d",num);
}
個(gè)人觀點(diǎn):
? 計(jì)算機(jī)是一門和數(shù)學(xué)相關(guān)的學(xué)科,隨著這門學(xué)科的發(fā)展,這種"本質(zhì)"似乎被弱化了.解法1是很普通的方法,一般人都是這種思路.而解法二則是從數(shù)學(xué)角度考慮.簡(jiǎn)潔,快速.
上次去神碼筆試,碰到一題
?? :給定一個(gè)數(shù),如7899,把各位數(shù)值相加7+8+9+9=33,3+3=6,用這種方法計(jì)算機(jī)下去,求最后得到的個(gè)位數(shù)
我給出的解法:
#include "stdio.h"
int main(){
???int i;
???scanf("%d",&i);
???printf("%d",i%9==0?9:i%9);
?? return 0
}//~end?
?
有6個(gè)英文字母,a,b,c ,d,e,f
?從中任意取N個(gè)(N<=6)來(lái)排列.
已知 a 只能與 b 相連,?
???????? b不能和e,f相連
?????????c不能和a相連
???????? d不能和 a ,e相連
???????????f 不能和?a,b相連
請(qǐng)打印出字母f或b 在末尾的組合順序,用Java實(shí)現(xiàn)
我的解答:
??? import java.util.*;
/**
?*
?* @author ShenXiaoliang
?*
?*/
public class DemoGraph {
?
?final static int VERTICE=6;
?
?private ArrayList<String> patheSet=new ArrayList<String>();
?
?private String[] ver={"a","b","c","d","e","f"};
?
?private int[][] graph=new int[6][6];
?
?private String path="";
?
?private boolean[] isVisit=new boolean[VERTICE];
?
?
?public DemoGraph() {
??
??initiGraph();
??for(int index=0;index<VERTICE;index++)
??depthSearch(index);
??show();
??
?}
?
?private void initiGraph(){
??graph[0][1]=1;
??graph[1][0]=1;
??graph[1][2]=1;
??graph[1][3]=1;
??graph[2][1]=1;
??graph[2][3]=1;
??graph[2][4]=1;
??graph[2][5]=1;
??graph[3][1]=1;
??graph[3][2]=1;
??graph[3][5]=1;
??graph[4][2]=1;
??graph[4][5]=1;
??graph[5][2]=1;
??graph[5][3]=1;
??graph[5][4]=1;
?}
?
?private void depthSearch(int start){
??
??isVisit[start]=true;
??path+=ver[start];
??if(path.charAt(path.length()-1)=='f'||path.charAt(path.length()-1)=='b') patheSet.add(path);
??for(int index=0;index<VERTICE;index++)
???if(graph[start][index]==1&&isVisit[index]==false)
????depthSearch(index);
???else continue;
??path=path.substring(0,path.length()-1);
??isVisit[start]=false;
?}
?
?
?private void show(){
??for(String pa:patheSet)
???System.out.println(pa);
?}
?/**
? * @param args
? */
?public static void main(String[] args) {
??// TODO Auto-generated method stub
??new DemoGraph();
?}
}
?????????
i thought about durain for time,not because i miss the test of it .just for curiosity。so ugly ,so smelly and so expensive.why so many persons love this strange fruit? is it really do delicious ?
today, i bought one.hehe.
well,i've no idea to deal the prickly,hard "stone".so it is reasonable to ask the worker of the supermark to get it . The flesh of durain is milk white with a little yellow,just like the ice cream for its softness. the feeling is good.
?i put a piece of the "cream" into my mouth,so carefully and nervous . wow ,the smell is still terrible,but the taste is unexpected delicious. soft,sweet,smooth.
?really good! Ubuntu is really a charming distribution of GUN/Linux . I've noticed it two months ago. The live CD instaills very easily and the "face" is beautiful . it is interesting that the X of Linux abroad is mostly Gnome while the domestic is KDE .well ,KDE looks more flamboyance for its class-style look . Gnome is simplicity comparatively. Why ? May be the people who use Linux aborad miss their Unix ,Hehe . Unix looks simplicity as well .
?Kubuntu is based on KDE ,it is the extending project of the Ubuntu ,seems less important than Dubuntu . But? frankly speaking ,Kubuntu looks more lovely ? i feel a lot about the importance of English these days.The foreign corporations and the top domestic companies ask for excellent skill of English. i am so soory now?and i should learn my English well .
? last weekend , we talked ablout if time back up for four years ,what we would do in the future 4 years .it is the very topic .some guy said he would find a girl firend ,while the other said he would not touch the on-line game . for me ,i said i would keep away from the C++ and devote myself to learing English?.and i said i had wasted a lot time on?some courses .
? most of us?will regret something in the past four years . we can not catch the gone time?.but i can try my best to?make good use?time nowaday .
?
? 華為筆試題:計(jì)算字符串“010111001100....”中‘0’和‘1’連續(xù)出現(xiàn)的次數(shù)。
#include<iostream>;
void main() {
???char *charArray="01000111100011100111100001";
???int max[2]?? ?={0,0};
???int count[2]? ={0,0};
? while(*charArray){
??????
? int?? index???? =*charArray-'0';
? count[index]++;
??count[index^1] =0;
? if(count[index]>max[index])
?????? ?max[index]=count[index];
? charArray++;
? }
?
?std:cout<<"Max times of 0 is"<<max[0]<<std:endl;
?std:cout<<"Max times of 1 is"<<max[1]<<std:endl;
}
//~:end the codes
程序代碼的藝術(shù)化,呵呵
自己想的一道題,算是30%原創(chuàng)吧?
String a=new String("Hello");
? a+="World";
?問(wèn):a的內(nèi)容最后是什么?
???????? 這兩個(gè)語(yǔ)句,共生成了幾個(gè)Java對(duì)象?
簡(jiǎn)單不?看樣子非常簡(jiǎn)單吧,呵呵。
第一問(wèn):a(確切地說(shuō)a引用的內(nèi)容)是HelloWorld
?
第二問(wèn): 兩個(gè)語(yǔ)句,一共生成了幾個(gè)對(duì)象?
????看第一個(gè)語(yǔ)句,說(shuō)實(shí)話,用這種方式初始化String,實(shí)在是代碼垃圾。這先不管啦。這個(gè)語(yǔ)句是老生長(zhǎng)談,一個(gè)或兩個(gè)對(duì)象。
??? 為何?第一次執(zhí)行時(shí)創(chuàng)建了二個(gè), 一個(gè)為字面量"Hello"(它本身是一個(gè)String對(duì)象), 一個(gè)為new String("Hello")(它是通過(guò)new創(chuàng)建的, 功能上和字面量"foo"完全一樣, 但卻是另一個(gè)對(duì)象).
第二次執(zhí)行時(shí), 只創(chuàng)建一個(gè), 即new String("Hello"), 這是因?yàn)? "Hello"作為String字面量, 是存在于String Pool里面的, 第二次使用它時(shí), 直接指向原有的String, 而不再創(chuàng)建新的String; 但new String("Hello")卻每執(zhí)行一次都創(chuàng)建一個(gè)新的,完全一樣的String對(duì)象.
???第二個(gè)語(yǔ)句呢?
???? 3個(gè)對(duì)象。
???? 首先是“World”,毋庸質(zhì)疑。
???? 那么然后呢?注意了,String是final類,不可改變。平時(shí)我們寫(xiě)Java會(huì)有個(gè)錯(cuò)覺(jué),stringA+stringB就以為是前者尾巴接上后者腦袋。的確,在C/C++里就是如此。一點(diǎn)兒錯(cuò)都沒(méi)有。
??? 但是Java不是,Java設(shè)計(jì)者為了更多方面的考慮,他們把String設(shè)計(jì)成了final。
??? 看一下JVM匯編指令吧
? 0:?aload_0
?? 1:?invokespecial?#1; //Method java/lang/Object."<init>":()V
?? 4:?return
static void inti();
? Code:
?? 0:?new?#2; //class java/lang/String
?? 3:?dup
?? 4:?ldc?#3; //String Hello
?? 6:?invokespecial?#4; //Method java/lang/String."<init>":(Ljava/lang/String;)V
?? 9:?astore_0
?? 10:?new?#5; //class java/lang/StringBuilder
?? 13:?dup
?? 14:?invokespecial?#6; //Method java/lang/StringBuilder."<init>":()V
?? 17:?aload_0
?? 18:?invokevirtual?#7; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
?? 21:?ldc?#3; //String Hello
?? 23:?invokevirtual?#7; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
?? 26:?invokevirtual?#8; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
?? 29:?astore_0
?? 30:?return
}
仔細(xì)看一下我做的標(biāo)記,JVM給我們生成了一個(gè)StringBuilder類。(我用的是JDK5,舊版本是StringBuffer類,單單這一點(diǎn)小改動(dòng)就能讓Java的速度提高很多)。讓后用append方法載入Hello和World兩個(gè)String的引用(明確地說(shuō)轉(zhuǎn)化成字符數(shù)組)。
當(dāng)載入完成后,StringBuilder實(shí)例調(diào)用toString,生成一個(gè)新的String實(shí)例(暫時(shí)稱為TempString)。
?最后把引用a指向TempString
總結(jié):兩句語(yǔ)句總共生成了4個(gè)或5個(gè)Java類實(shí)例
PS:Java中沒(méi)有指針實(shí)在是太不方便了。特別是在操作原始數(shù)據(jù)類型的時(shí)候。個(gè)人認(rèn)為Java應(yīng)該在這點(diǎn)上學(xué)學(xué)C#。指針不是洪水猛獸,對(duì)優(yōu)秀程序員而言,指針是編程中的一種享受。
??????? 希望“海豚”(Java7)能出現(xiàn)指針吧---很不現(xiàn)實(shí),還是等開(kāi)源后的Java版本吧
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
30 | 31 | 1 | 2 | 3 | 4 | 5 | |||
6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
20 | 21 | 22 | 23 | 24 | 25 | 26 | |||
27 | 28 | 29 | 30 | 31 | 1 | 2 | |||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
常用鏈接
留言簿(3)
隨筆分類
隨筆檔案
- 2007年6月 (3)
- 2007年1月 (1)
- 2006年11月 (1)
- 2006年10月 (6)
- 2006年9月 (1)
- 2006年8月 (2)
- 2006年7月 (8)
- 2006年6月 (1)
- 2006年5月 (3)
- 2006年4月 (4)
相冊(cè)
搜索
最新評(píng)論

- 1.?re: 一點(diǎn)小感想:為什么那么多人說(shuō)Java慢???[未登錄](méi)
- 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
- --夏
- 2.?re: 一點(diǎn)小感想:為什么那么多人說(shuō)Java慢???[未登錄](méi)
-
莫名被最后一句話戳中笑點(diǎn)@fjchenq
- --aa
- 3.?re: 一點(diǎn)小感想:為什么那么多人說(shuō)Java慢???
- 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
- --嗷嗷嗷
- 4.?re: 一點(diǎn)小感想:為什么那么多人說(shuō)Java慢???[未登錄](méi)
- c++存在一個(gè)函數(shù)表,訪問(wèn)一段代碼至少要訪問(wèn)兩次內(nèi)存,所以在對(duì)性能要求很高的操作系統(tǒng)內(nèi)核上不適宜使用
- --光光
- 5.?re: 一點(diǎn)小感想:為什么那么多人說(shuō)Java慢???
- Java桌面應(yīng)用慢到死!垃圾一樣的東西
- --的