java.sql.*;
漾濞網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,漾濞網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為漾濞千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的漾濞做網(wǎng)站的公司定做!
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StuDataBase implements ActionListener {
Connection con;
Statement state;
// 連接數(shù)據(jù)庫的賬號(hào)和密碼
String conAccount;
String conPassword;
JTextField textAccount;
1、拿到代碼查看項(xiàng)目當(dāng)中是否有readme這樣的文件,如果沒有查看是否有文檔之類的
2、代碼當(dāng)中沒有文檔,那么就想你的同事或者其他人要這個(gè)框架的介紹或者資料
3、先請(qǐng)教別人這個(gè)框架的大體思路
4、自己獨(dú)立去按照文檔或者其他人說的思路去看代碼
5、不懂的地方全部記錄下面,一次行去問,有的時(shí)候很多問題在你看到后面的東西的時(shí)候就自然明白了
6、看懂了代碼之后自己嘗試著寫一個(gè),看自己的理解是否正確就這么多了。
本來不想回答,翻到下面那些答復(fù)實(shí)在看不過去,就花點(diǎn)功夫整理下吧,希望對(duì)有人心能有幫助。
閱讀分析源代碼,一些有效的方法是:
1、閱讀源代碼的說明文檔和API文檔。
2、如果源代碼有用法示例或向?qū)?,先閱讀這個(gè)。
3、了解整個(gè)項(xiàng)目的模塊結(jié)構(gòu),可以按模塊進(jìn)行閱讀。
4、隨時(shí)使用查找功能(或超鏈接)閱讀關(guān)聯(lián)類或關(guān)聯(lián)方法。
5、對(duì)于有疑問的地方,不妨寫幾行單元測(cè)試。
6、由淺入深,由易到難,多閱讀優(yōu)秀的開源項(xiàng)目,代碼閱讀水平會(huì)突飛猛進(jìn)。
package?test2;
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.Set;
public?class?JavaCodeAnalyzer?{
public?static?void?analyze(File?file)?throws?IOException{
//FileOutputStream?fos?=?new?FileOutputStream("F;"+File.separator+"result.txt");
if(!(file.getName().endsWith(".txt")||file.getName().endsWith(".java"))){
System.out.println("輸入的分析文件格式不對(duì)!");
}
InputStream?is=?new?FileInputStream(file);
BufferedReader?br=?new?BufferedReader(new?InputStreamReader(is));
String?temp;
int?count=0;
int?countSpace=0;
int?countCode=0;
int?countDesc=0;
MapString,?Integer?map?=?getKeyWords();
while((temp=br.readLine())!=null){
countKeys(temp,?map);
count++;
if(temp.trim().equals("")){
countSpace++;
}else?if(temp.trim().startsWith("/*")||temp.trim().startsWith("http://")){
countDesc++;
}else{
countCode++;
}
}
System.out.printf("代碼行數(shù):"+countCode+"占總行數(shù)的%4.2f\n",(double)countCode/count);
System.out.printf("空行數(shù):"+countSpace+"占總行數(shù)的%4.2f\n",(double)countSpace/count);
System.out.printf("注釋行數(shù):"+countDesc+"占總行數(shù)的%4.2f\n",(double)countDesc/count);
System.out.println("總行數(shù):"+count);
System.out.println("出現(xiàn)最多的5個(gè)關(guān)鍵字是:");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
}
public?static?void?main(String[]?args)?{
getKeyWords();
File?file?=?new?File("F://Test.java");
try?{
analyze(file);
}?catch?(IOException?e)?{
//?TODO?自動(dòng)生成?catch?塊
e.printStackTrace();
}
}
public?static?MapString,Integer?getKeyWords(){
MapString,Integer?map?=?new?HashMapString,?Integer();
String[]keywords?=?{"abstract","assert","boolean","break","byte","case","catch","char","class","continue","default","do","double","else","enum","extends","final","finally","float","for","if","implements","import","instanceof","int","interface","long","native","new","package","private","protected","public","return","????strictfp","short","static","super","????switch","synchronized","this","throw","throws","transient","try","void","volatile","while","goto","const"};
for(String?s:keywords){
map.put(s,?0);
}
return?map;
}
public?static?void?countKeys(String?s,MapString,Integer?map){
SetString?keys?=?map.keySet();
for(String?ss:keys){
if(s.indexOf(ss)!=-1){
map.put(ss,?map.get(ss)+1);
}
}
}
}
上班沒啥時(shí)間了,還有點(diǎn)沒寫完,你在想想。